using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;
using OracleInternal.Common;
using OracleInternal.SqlAndPlsqlParser.LocalParsing;
using OracleInternal.TTC;
using OracleInternal.TTC.Accessors;

namespace OracleInternal.ServiceObjects
{
	internal class OracleCommandImpl
	{
		private static string s_replaceString = "\r\n";

		private const int ROWS_TO_FETCH = 25;

		internal SqlStatementType m_sqlStatementType;

		private byte[] m_commandTextByteStream;

		internal SQLMetaData m_sqlMetaData;

		private int m_rowsToFetch = 25;

		internal Accessor[] m_bindAccessors;

		internal BindDirection[] m_bindDirectionsFromServer;

		internal bool m_bHasReturningClause;

		internal long m_executionId;

		internal bool m_bServerExecutionComplete;

		internal object m_lockCancel = new object();

		internal AutoResetEvent m_continueCancel = new AutoResetEvent(initialState: false);

		internal AutoResetEvent m_cancelExecutionEvent = new AutoResetEvent(initialState: false);

		internal List<TTCResultSet> m_implicitRSList;

		internal int m_numReturningParams;

		internal long m_fetchSize;

		internal int m_arrayBindCount;

		internal bool m_bBindByName;

		internal long[] m_rowsAffectedPerBind;

		internal static int m_clientRegistrationId = 0;

		internal OracleIntervalDS m_sessionTimeZone;

		internal bool m_addToStatementCache = true;

		internal bool m_addRowid;

		internal bool m_addRowidDoneImplicitly;

		internal bool m_foundExplicitRowidInSql;

		internal bool m_bPooled;

		internal bool m_bExecutingForFill;

		internal bool m_bReturnPSTypes;

		private string m_pooledCmdText;

		internal OracleCommandImpl()
		{
		}

		internal void Init()
		{
			m_sqlStatementType = SqlStatementType.SELECT;
			m_commandTextByteStream = null;
			m_sqlMetaData = null;
			m_rowsToFetch = 25;
			m_bindAccessors = null;
			m_bindDirectionsFromServer = null;
			m_bHasReturningClause = false;
			m_bServerExecutionComplete = false;
			m_numReturningParams = 0;
			m_fetchSize = 0L;
			m_arrayBindCount = 0;
			m_bBindByName = ConfigBaseClass.m_BindByName;
			m_clientRegistrationId = 0;
			m_sessionTimeZone = OracleIntervalDS.Null;
			m_addToStatementCache = true;
			m_addRowid = false;
			m_addRowidDoneImplicitly = false;
			m_foundExplicitRowidInSql = false;
			m_executionId = 0L;
		}

		internal void Copy(OracleCommandImpl orclCmdImpl)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Copy);
			}
			try
			{
				m_fetchSize = orclCmdImpl.m_fetchSize;
				m_arrayBindCount = orclCmdImpl.m_arrayBindCount;
				m_bBindByName = orclCmdImpl.m_bBindByName;
				m_addToStatementCache = orclCmdImpl.m_addToStatementCache;
				m_addRowid = orclCmdImpl.m_addRowid;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Copy, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Copy);
				}
			}
		}

		private bool CanUseOptimizeExecute(SqlStatementType stmtType, long numRowsToFetch, long numIterations, bool bsnapshot, bool bChangeNtfReq)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CanUseOptimizeExecute);
			}
			bool result = false;
			try
			{
				switch (stmtType)
				{
				case SqlStatementType.SELECT:
					numIterations = numRowsToFetch;
					break;
				case SqlStatementType.DML:
					numIterations = m_arrayBindCount;
					break;
				}
				if (((stmtType == SqlStatementType.SELECT && numIterations < 32768) || (stmtType == SqlStatementType.DML && numIterations <= 0) || (stmtType == SqlStatementType.PLSQL && numIterations == 1)) && !bChangeNtfReq && !bsnapshot)
				{
					result = true;
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CanUseOptimizeExecute, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CanUseOptimizeExecute);
				}
			}
		}

		internal void Cancel(OracleConnectionImpl connImpl, long cancelExecutionId)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Cancel);
			}
			m_cancelExecutionEvent.Set();
			try
			{
				if (m_bServerExecutionComplete)
				{
					return;
				}
				lock (m_lockCancel)
				{
					if (!m_bServerExecutionComplete && cancelExecutionId == m_executionId && m_continueCancel.WaitOne(2000))
					{
						connImpl.m_marshallingEngine.m_oracleCommunication.Break();
					}
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Cancel, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.Cancel);
				}
			}
		}

		internal static void ValidateStatementCacheSize(OracleConnectionImpl connectionImpl)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ValidateStatementCacheSize);
			}
			try
			{
				if (connectionImpl.m_pm != null && connectionImpl.m_pm.MaxAllowedValue != int.MaxValue && connectionImpl.m_statementCache.m_maxCacheSize > connectionImpl.m_pm.MaxAllowedValue)
				{
					int num = ((connectionImpl.m_pm.m_recommendedSCS <= connectionImpl.m_pm.MaxAllowedValue) ? connectionImpl.m_pm.m_recommendedSCS : connectionImpl.m_pm.MaxAllowedValue);
					if (connectionImpl.m_statementCache.Count > num)
					{
						connectionImpl.PurgeStatementCache(num);
					}
					connectionImpl.m_statementCache.m_maxCacheSize = num;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ValidateStatementCacheSize, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ValidateStatementCacheSize);
				}
			}
		}

		internal int VerifyExecution(OracleConnectionImpl connectionImpl, out int cursorId, bool bThrowArrayBindRelatedErrors, ref OracleException exceptionForArrayBindDML, out bool hasMoreRowsInDB, bool bFirstIterationDone = false)
		{
			return connectionImpl.VerifyExecution(out cursorId, bThrowArrayBindRelatedErrors, m_sqlStatementType, m_arrayBindCount, ref exceptionForArrayBindDML, out hasMoreRowsInDB, bFirstIterationDone);
		}

		internal static void TrimCommentsFromSQL(ref string cmdText)
		{
			if (string.IsNullOrWhiteSpace(cmdText))
			{
				return;
			}
			string cmdText2 = cmdText.TrimStart();
			string text = string.Empty;
			char[] trimChars = new char[5]
			{
				' ',
				'(',
				'\r',
				'\t',
				'\n'
			};
			try
			{
				TrimStringsFromSQL(ref cmdText2);
				int num = cmdText2.IndexOf("--");
				int num2 = cmdText2.IndexOf("/*");
				if (num == -1 && num2 == -1)
				{
					text = cmdText2;
				}
				else
				{
					while (num != -1 || num2 != -1)
					{
						if (num > -1 && (num2 <= -1 || num2 > num))
						{
							int num3 = cmdText2.IndexOf('\n', num + 2);
							if (num3 == -1)
							{
								num3 = cmdText2.Length - 1;
							}
							text += cmdText2.Substring(0, num);
							cmdText2 = cmdText2.Substring(num3 + 1);
						}
						else if (num2 > -1)
						{
							int num4 = cmdText2.IndexOf("*/", 2);
							if (num4 == -1)
							{
								throw new FormatException();
							}
							text += cmdText2.Substring(0, num2);
							cmdText2 = cmdText2.Substring(num4 + 2);
						}
						if (cmdText2 != null)
						{
							cmdText2 = cmdText2.TrimStart(trimChars);
						}
						num = cmdText2.IndexOf("--");
						num2 = cmdText2.IndexOf("/*");
					}
					if (cmdText2.Length > 0)
					{
						text += cmdText2;
					}
				}
			}
			catch
			{
				text = cmdText;
			}
			text = (cmdText = text.TrimStart(trimChars));
		}

		internal static void TrimStringsFromSQL(ref string cmdText)
		{
			if (cmdText.IndexOf('\'') == -1)
			{
				return;
			}
			int length = cmdText.Length;
			StringBuilder stringBuilder = new StringBuilder(length);
			bool flag = false;
			bool flag2 = false;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.TrimStringsFromSQL);
			}
			try
			{
				for (int i = 0; i < length; i++)
				{
					char c = cmdText[i];
					switch (c)
					{
					case '\'':
						if (!flag2)
						{
							if (!flag)
							{
								flag = true;
								stringBuilder.Append('\'');
							}
							else if (i + 1 != length && cmdText[i + 1] == '\'')
							{
								i++;
							}
							else
							{
								flag = false;
								stringBuilder.Append('\'');
							}
							continue;
						}
						break;
					case '"':
						if (!flag)
						{
							flag2 = !flag2;
						}
						break;
					}
					if (!flag)
					{
						stringBuilder.Append(c);
					}
				}
				if (!flag && !flag2)
				{
					cmdText = stringBuilder.ToString();
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.TrimStringsFromSQL, ex);
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.TrimStringsFromSQL);
				}
			}
		}

		internal int ExecuteNonQuery(string commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, int longFetchSize, long clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, out long[] scnFromExecution, out OracleParameterCollection bindByPositionParamColl, ref bool bBindParamPresent, out OracleException exceptionForArrayBindDML, OracleConnection connection, ref OracleLogicalTransaction oracleLogicalTransaction, bool isFromEF = false)
		{
			bool flag = false;
			bool flag2 = false;
			Accessor[] defineAccessors = null;
			ColumnDescribeInfo[] cachedParamMetadata = null;
			CachedStatement cachedStmnt = null;
			SQLMetaData metadata = null;
			SQLInfo sqlInfo = null;
			int cursorId = 0;
			ArrayList placeHolderCollection = null;
			bindByPositionParamColl = null;
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			bool? bIsDefineInSelect = false;
			string cmdText = commandText;
			m_sqlMetaData = null;
			scnFromExecution = null;
			IEnumerable<OracleLpStatement> enumerable = null;
			bool flag3 = false;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteNonQuery);
			}
			if (m_implicitRSList != null && m_implicitRSList.Count > 0)
			{
				CloseImplicitRefCursors(connectionImpl);
				m_implicitRSList.Clear();
			}
			try
			{
				BindDirection[] bindDirections = null;
				if (connectionImpl.m_statementCache != null && (!connectionImpl.m_marshallingEngine.m_bDRCPConnection || connectionImpl.m_marshallingEngine.m_bDRCPSessionAttached))
				{
					ValidateStatementCacheSize(connectionImpl);
					connectionImpl.m_statementCache.Get(commandText, out cachedStmnt, out metadata, out sqlInfo);
					if (cachedStmnt != null)
					{
						cursorId = cachedStmnt.m_cursorId;
						m_bindAccessors = cachedStmnt.m_bindAccessors;
						cachedParamMetadata = cachedStmnt.m_bindParamMetadata;
						scnFromExecution = cachedStmnt.m_scnFromExecution;
						placeHolderCollection = cachedStmnt.m_placeHolderCollection;
						bBindParamPresent = cachedStmnt.m_bBindParamPresent;
						bindDirections = cachedStmnt.m_bindDirections;
						m_bindDirectionsFromServer = cachedStmnt.m_bindDirections;
						enumerable = ((cachedStmnt.statementdata != null) ? cachedStmnt.statementdata.parsedStmt : null);
						flag = true;
					}
				}
				if (sqlInfo != null)
				{
					m_commandTextByteStream = sqlInfo.m_SQLcommandTextByteStream;
					m_sqlStatementType = sqlInfo.m_SQLStatementType;
				}
				else
				{
					switch (commandType)
					{
					case CommandType.StoredProcedure:
						m_sqlStatementType = SqlStatementType.PLSQL;
						break;
					case CommandType.TableDirect:
						m_sqlStatementType = SqlStatementType.SELECT;
						break;
					default:
						TrimCommentsFromSQL(ref cmdText);
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
						{
							m_sqlStatementType = GetSqlStatementType(cmdText, ref bIsDefineInSelect);
						}
						break;
					}
					string text = commandText;
					if (!connectionImpl.m_isDb11gR1OrHigher && (m_sqlStatementType == SqlStatementType.PLSQL || cmdText.StartsWith("create", StringComparison.InvariantCultureIgnoreCase)))
					{
						text = commandText.Replace("\r\n", "\n");
					}
					m_commandTextByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text, 0, text.Length);
				}
				flag2 = (m_sqlMetaData = metadata) != null;
				if (!flag || (bBindParamPresent && m_bBindByName && placeHolderCollection == null))
				{
					if (m_bBindByName)
					{
						placeHolderCollection = new ArrayList();
					}
					switch (commandType)
					{
					case CommandType.Text:
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
						{
							ParseCommandText(cmdText, ref bBindParamPresent, ref placeHolderCollection);
						}
						break;
					case CommandType.TableDirect:
						bBindParamPresent = false;
						break;
					}
				}
				if (m_bBindByName && paramColl != null && paramColl.Count > 0)
				{
					if (commandType == CommandType.StoredProcedure)
					{
						bindByPositionParamColl = ReorderBindByNameBasedParameterCollectionForStoredProcedure(paramColl);
					}
					else
					{
						bindByPositionParamColl = GetBindByPositionBasedParameterCollection(paramColl, placeHolderCollection);
					}
				}
				else
				{
					bindByPositionParamColl = paramColl;
				}
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.SQL, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteNonQuery, commandText);
				}
				bool flag4 = false;
				bool bBindMetadataModified = false;
				TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
				marshalBindValuesHelper.m_bWriteOutParamVal = cursorId <= 0;
				if (cachedStmnt != null)
				{
					marshalBindValuesHelper.m_bAllInBinds = cachedStmnt.m_bAllInBinds;
					marshalBindValuesHelper.m_bAllOutBinds = cachedStmnt.m_bAllOutBinds;
				}
				if (bBindParamPresent && bindByPositionParamColl != null)
				{
					marshalBindValuesHelper.m_bindDirections = bindDirections;
					marshalBindValuesHelper.m_sqlStmtType = m_sqlStatementType;
					if (m_bindAccessors == null || m_bindAccessors.Length != paramColl.Count)
					{
						m_bindAccessors = new Accessor[paramColl.Count];
					}
					ProcessParameters(bindByPositionParamColl, connectionImpl, cachedParamMetadata, ref bBindMetadataModified, isFromEF && m_sqlStatementType == SqlStatementType.SELECT, ref marshalBindValuesHelper);
				}
				else
				{
					m_bindAccessors = null;
					m_bindDirectionsFromServer = null;
					m_arrayBindCount = 0;
				}
				if (flag && !bBindMetadataModified && cachedStmnt.m_cursorId > 0 && CanUseOptimizeExecute(m_sqlStatementType, m_rowsToFetch, (m_arrayBindCount == 0) ? 1 : m_arrayBindCount, bsnapshot: false, orclDependencyImpl != null))
				{
					flag4 = true;
				}
				int noOfRowsFetched = 0;
				int num = 0;
				long queryId = 0L;
				DataUnmarshaller dataUnmarshaller = null;
				if (scnFromExecution != null)
				{
					scnFromExecution[0] = 0L;
					scnFromExecution[1] = 0L;
				}
				else
				{
					scnFromExecution = new long[2];
				}
				if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
				{
					CheckForReturningClause(cmdText, m_sqlStatementType, sqlInfo, commandType, bindByPositionParamColl, placeHolderCollection, bBindParamPresent, commandText);
				}
				bool bDisableCompressedFetch = m_bHasReturningClause || SqlStatementType.PLSQL == m_sqlStatementType || (cachedStmnt?.m_bDisableCompressedFetch ?? false);
				int num2 = -1;
				try
				{
					num2 = connectionImpl.WaitForConnectionForExecution(m_cancelExecutionEvent);
					m_continueCancel.Set();
					connectionImpl.AddAllPiggyBackRequests();
					TTCExecuteSql executeSqlObject = connectionImpl.ExecuteSqlObject;
					if (flag4)
					{
						if (connection != null)
						{
							oracleLogicalTransaction = connection.OracleLogicalTransaction;
						}
						executeSqlObject.SendReExecuteRequest(connectionImpl, cursorId, 0L, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, m_arrayBindCount, ref marshalBindValuesHelper);
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB = false;
						num = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB);
					}
					else
					{
						bool parse = !flag || cursorId == 0;
						bool fetch = (flag && cursorId > 0) || m_bHasReturningClause || m_sqlStatementType == SqlStatementType.PLSQL;
						bool num3 = m_arrayBindCount > 1 && SqlStatementType.PLSQL == m_sqlStatementType;
						bool flag5 = false;
						bool bThrowArrayBindRelatedErrors = true;
						if (num3 && (!flag || (flag && !cachedStmnt.m_bAllInBinds && !cachedStmnt.m_bAllOutBinds)))
						{
							flag5 = true;
						}
						if (connection != null)
						{
							oracleLogicalTransaction = connection.OracleLogicalTransaction;
						}
						executeSqlObject.SendExecuteRequest(connectionImpl, (flag && cursorId > 0) ? null : m_commandTextByteStream, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, null, 0L, parse, execute: true, fetch, define: false, !flag5 && connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, longFetchSize, flag5 ? 1 : m_arrayBindCount, null, ref marshalBindValuesHelper, 0);
						if (marshalBindValuesHelper.m_bindDirections == null && marshalBindValuesHelper.m_paramValueArray != null)
						{
							marshalBindValuesHelper.ResetBindDirections(paramColl.Count);
							marshalBindValuesHelper.m_bAllInBinds = true;
						}
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						if (flag5)
						{
							bThrowArrayBindRelatedErrors = false;
						}
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB2 = false;
						num = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors, ref exceptionForArrayBindDML, out hasMoreRowsInDB2);
						if (flag5)
						{
							if (marshalBindValuesHelper.m_bAllInBinds || marshalBindValuesHelper.m_bAllOutBinds)
							{
								if (connection != null)
								{
									oracleLogicalTransaction = connection.OracleLogicalTransaction;
								}
								executeSqlObject.SendExecuteRequest(connectionImpl, null, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, null, 0L, parse: false, execute: true, fetch: true, define: false, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, longFetchSize, m_arrayBindCount - 1, null, ref marshalBindValuesHelper, 1);
								executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
								num += VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB2, bFirstIterationDone: true);
							}
							else
							{
								bool bAutoCommit = false;
								for (int i = 1; i < m_arrayBindCount; i++)
								{
									if (i == m_arrayBindCount - 1)
									{
										bAutoCommit = connectionImpl.m_autoCommit;
									}
									if (connection != null)
									{
										oracleLogicalTransaction = connection.OracleLogicalTransaction;
									}
									executeSqlObject.SendExecuteRequest(connectionImpl, null, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, null, 0L, parse: false, execute: true, fetch: true, define: false, bAutoCommit, bDisableCompressedFetch, m_sqlStatementType, longFetchSize, 1, null, ref marshalBindValuesHelper, i);
									executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
									num += VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB2, bFirstIterationDone: true);
								}
							}
						}
					}
					lock (m_lockCancel)
					{
						m_bServerExecutionComplete = true;
						if (m_executionId >= long.MaxValue)
						{
							m_executionId = 0L;
						}
						else
						{
							m_executionId++;
						}
					}
					if (connectionImpl.m_oracleCommunication.InBreakResetMode())
					{
						connectionImpl.m_marshallingEngine.ProcessReset();
					}
					if (executeSqlObject.m_bSessionTimeZoneUpdated)
					{
						connectionImpl.m_sessionTimeZone = new OracleIntervalDS(executeSqlObject.m_sessionTimeZone);
						executeSqlObject.m_bSessionTimeZoneUpdated = false;
					}
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (m_sqlMetaData != null)
					{
						m_sqlMetaData.pCommandText = commandText;
						if (!flag2)
						{
							metadata = m_sqlMetaData;
						}
					}
					m_bindDirectionsFromServer = marshalBindValuesHelper.m_bindDirections;
					if (orclDependencyImpl != null)
					{
						orclDependencyImpl.m_bIsEnabled = orclDependencyImpl.m_bIsRegistered;
						if (orclDependencyImpl.m_bQueryBasedNTFN && !orclDependencyImpl.m_queryIDList.Contains(queryId))
						{
							lock (orclDependencyImpl.m_syncList)
							{
								if (!orclDependencyImpl.m_queryIDList.Contains(queryId))
								{
									orclDependencyImpl.m_queryIDList.Add(queryId);
								}
							}
						}
					}
					if (exceptionForArrayBindDML != null)
					{
						return num;
					}
					if ((!bIsDefineInSelect.HasValue || bIsDefineInSelect == false) && (m_sqlStatementType == SqlStatementType.DML || m_sqlStatementType == SqlStatementType.SELECT || m_sqlStatementType == SqlStatementType.PLSQL) && !flag && connectionImpl.m_statementCache != null && m_addToStatementCache)
					{
						cachedStmnt = new CachedStatement();
						cachedStmnt.sqlInfo = new SQLInfo
						{
							m_SQLcommandTextByteStream = m_commandTextByteStream,
							m_SQLhasReturningClause = m_bHasReturningClause,
							m_SQLStatementType = m_sqlStatementType
						};
						cachedStmnt.statementdata = metadata;
						cachedStmnt.m_cursorId = cursorId;
						cachedStmnt.m_bindAccessors = m_bindAccessors;
						cachedStmnt.m_bindParamMetadata = marshalBindValuesHelper.m_paramCollInfoArray;
						cachedStmnt.m_scnFromExecution = scnFromExecution;
						cachedStmnt.m_placeHolderCollection = placeHolderCollection;
						cachedStmnt.m_bBindParamPresent = bBindParamPresent;
						cachedStmnt.m_bindDirections = marshalBindValuesHelper.m_bindDirections;
						cachedStmnt.m_bAllInBinds = marshalBindValuesHelper.m_bAllInBinds;
						cachedStmnt.m_bAllOutBinds = marshalBindValuesHelper.m_bAllOutBinds;
						if (cachedStmnt.statementdata != null && enumerable != null)
						{
							foreach (OracleLpStatement item in enumerable)
							{
								item.m_vODPContext = null;
							}
							cachedStmnt.statementdata.parsedStmt = enumerable;
						}
					}
					if (cachedStmnt != null && connectionImpl.m_statementCache != null)
					{
						if (cachedStmnt.m_cursorId == 0)
						{
							cachedStmnt.m_cursorId = cursorId;
						}
						CachedStatement cachedStatement = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
						if (cachedStatement != null && cachedStatement.m_cursorId > 0)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement.m_cursorId);
						}
					}
					else
					{
						connectionImpl.AddCursorIdToBeClosed(cursorId);
					}
				}
				finally
				{
					m_continueCancel.Reset();
					if (num2 > 0)
					{
						connectionImpl.m_connectionFreeToUseEvent.Set();
					}
					else if (flag)
					{
						CachedStatement cachedStatement2 = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
						if (cachedStatement2 != null)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement2.m_cursorId);
						}
					}
				}
				if (m_bHasReturningClause && bMoreThanOneRowAffectedByDmlWithRetClause)
				{
					throw new OracleException(24369, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24369));
				}
				if (SqlStatementType.DML != m_sqlStatementType)
				{
					num = -1;
				}
				return num;
			}
			catch (Exception ex)
			{
				if (bindByPositionParamColl != null)
				{
					foreach (OracleParameter item2 in bindByPositionParamColl)
					{
						item2.PreBindFree();
					}
				}
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteNonQuery, ex);
				if (ex is OracleException)
				{
					connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteNonQuery);
				}
			}
		}

		internal int ExecuteXmlQuery(string commandText, OracleParameterCollection paramColl, CommandType commandType, OracleXmlCommandType xmlCommandType, OracleConnectionImpl connectionImpl, int longFetchSize, long clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, OracleConnection connection, out long[] scnFromExecution, out OracleParameterCollection bindByPositionParamColl, ref bool bBindParamPresent, ref OracleXmlQueryProperties xmlQueryProperties, out OracleException exceptionForArrayBindDML, out bool transform, out int numberOfUserParameters, ref OracleLogicalTransaction oracleLogicalTransaction, bool isFromEF = false, bool isOracle8i = false, bool wantResult = false)
		{
			bool flag = false;
			bool flag2 = false;
			Accessor[] defineAccessors = null;
			ColumnDescribeInfo[] cachedParamMetadata = null;
			CachedStatement cachedStmnt = null;
			SQLMetaData metadata = null;
			SQLInfo sqlInfo = null;
			int cursorId = 0;
			ArrayList placeHolderCollection = null;
			bindByPositionParamColl = null;
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			bool? bIsDefineInSelect = null;
			OracleParameter oracleParameter = null;
			OracleParameter oracleParameter2 = null;
			OracleClob oracleClob = null;
			OracleParameter oracleParameter3 = null;
			OracleClob oracleClob2 = null;
			m_sqlMetaData = null;
			scnFromExecution = null;
			int num = 0;
			numberOfUserParameters = 0;
			transform = false;
			IEnumerable<OracleLpStatement> enumerable = null;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlQuery);
			}
			try
			{
				if (m_implicitRSList != null && m_implicitRSList.Count > 0)
				{
					CloseImplicitRefCursors(connectionImpl);
					m_implicitRSList.Clear();
				}
				if (xmlQueryProperties == null)
				{
					xmlQueryProperties = new OracleXmlQueryProperties();
				}
				if (xmlQueryProperties.Xslt != null && xmlQueryProperties.Xslt.Length != 0)
				{
					transform = true;
				}
				string text = ":OracleResult$";
				string parameterName = ":OracleXslDoc$";
				string parameterName2 = ":OracleSqlQuery$";
				BindDirection[] bindDirections = null;
				flag2 = (m_sqlMetaData = metadata) != null;
				bool flag3 = false;
				bool flag4 = false;
				if (!flag || (bBindParamPresent && m_bBindByName && placeHolderCollection == null))
				{
					if (m_bBindByName)
					{
						placeHolderCollection = new ArrayList();
					}
					switch (commandType)
					{
					case CommandType.Text:
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
						{
							ParseCommandText(commandText, ref bBindParamPresent, ref placeHolderCollection);
						}
						break;
					case CommandType.TableDirect:
						bBindParamPresent = false;
						break;
					}
				}
				if (m_bBindByName && paramColl != null && paramColl.Count > 0)
				{
					if (commandType == CommandType.StoredProcedure)
					{
						bindByPositionParamColl = ReorderBindByNameBasedParameterCollectionForStoredProcedure(paramColl);
					}
					else
					{
						bindByPositionParamColl = GetBindByPositionBasedParameterCollection(paramColl, placeHolderCollection, bXmlQuerySave: true);
					}
				}
				else
				{
					bindByPositionParamColl = paramColl;
				}
				if (bindByPositionParamColl != null && bindByPositionParamColl.Count > 0)
				{
					numberOfUserParameters = bindByPositionParamColl.Count;
					if (!m_bBindByName)
					{
						throw new InvalidOperationException();
					}
				}
				num = numberOfUserParameters;
				if (wantResult)
				{
					num++;
				}
				if (transform)
				{
					num++;
				}
				if (isOracle8i)
				{
					num++;
				}
				BuildXmlQueryCommandText(wantResult, text, isOracle8i, commandText, bindByPositionParamColl, xmlCommandType, xmlQueryProperties);
				m_sqlStatementType = SqlStatementType.PLSQL;
				if (connectionImpl.m_statementCache != null && (!connectionImpl.m_marshallingEngine.m_bDRCPConnection || connectionImpl.m_marshallingEngine.m_bDRCPSessionAttached))
				{
					ValidateStatementCacheSize(connectionImpl);
					connectionImpl.m_statementCache.Get(m_pooledCmdText, out cachedStmnt, out metadata, out sqlInfo);
					if (cachedStmnt != null)
					{
						cursorId = cachedStmnt.m_cursorId;
						m_bindAccessors = cachedStmnt.m_bindAccessors;
						cachedParamMetadata = cachedStmnt.m_bindParamMetadata;
						scnFromExecution = cachedStmnt.m_scnFromExecution;
						placeHolderCollection = cachedStmnt.m_placeHolderCollection;
						bBindParamPresent = cachedStmnt.m_bBindParamPresent;
						bindDirections = cachedStmnt.m_bindDirections;
						m_bindDirectionsFromServer = cachedStmnt.m_bindDirections;
						enumerable = ((cachedStmnt.statementdata != null) ? cachedStmnt.statementdata.parsedStmt : null);
						flag = true;
					}
				}
				if (sqlInfo != null)
				{
					m_commandTextByteStream = sqlInfo.m_SQLcommandTextByteStream;
					m_sqlStatementType = sqlInfo.m_SQLStatementType;
				}
				else
				{
					switch (commandType)
					{
					case CommandType.StoredProcedure:
						m_sqlStatementType = SqlStatementType.PLSQL;
						break;
					case CommandType.TableDirect:
						m_sqlStatementType = SqlStatementType.SELECT;
						break;
					default:
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag4)
						{
							m_sqlStatementType = GetSqlStatementType(m_pooledCmdText, ref bIsDefineInSelect);
						}
						break;
					}
					m_commandTextByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(m_pooledCmdText, 0, m_pooledCmdText.Length);
				}
				if (num > 0 && bindByPositionParamColl == null)
				{
					bindByPositionParamColl = new OracleParameterCollection();
				}
				if (isOracle8i)
				{
					if (commandText.Length > 32512)
					{
						oracleParameter3 = new OracleParameter(parameterName2, OracleDbType.Clob);
						oracleParameter3.Direction = ParameterDirection.Input;
						oracleClob2 = new OracleClob(connection);
						oracleClob2.Append(commandText.ToCharArray(), 0, commandText.Length);
						oracleParameter3.Value = oracleClob2;
						bindByPositionParamColl.Add(oracleParameter3);
					}
					else
					{
						oracleParameter3 = new OracleParameter(parameterName2, OracleDbType.Varchar2);
						oracleParameter3.Direction = ParameterDirection.Input;
						oracleParameter3.Value = commandText;
						bindByPositionParamColl.Add(oracleParameter3);
					}
					bBindParamPresent = true;
				}
				if (transform)
				{
					if (xmlQueryProperties.Xslt.Length > 32512 || isOracle8i)
					{
						oracleParameter2 = new OracleParameter(parameterName, OracleDbType.Clob);
						oracleParameter2.Direction = ParameterDirection.Input;
						oracleClob = new OracleClob(connection);
						oracleClob.Append(xmlQueryProperties.Xslt.ToCharArray(), 0, xmlQueryProperties.Xslt.Length);
						oracleParameter2.Value = oracleClob;
						bindByPositionParamColl.Add(oracleParameter2);
					}
					else
					{
						oracleParameter2 = new OracleParameter(parameterName, OracleDbType.Varchar2);
						oracleParameter2.Direction = ParameterDirection.Input;
						oracleParameter2.Value = xmlQueryProperties.Xslt;
						bindByPositionParamColl.Add(oracleParameter2);
					}
					bBindParamPresent = true;
				}
				if (wantResult)
				{
					oracleParameter = new OracleParameter(text, OracleDbType.Clob);
					oracleParameter.Direction = ParameterDirection.Output;
					bindByPositionParamColl.Add(oracleParameter);
					bBindParamPresent = true;
				}
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.SQL, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlQuery, m_pooledCmdText);
				}
				bool flag5 = false;
				bool bBindMetadataModified = false;
				TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
				marshalBindValuesHelper.m_bWriteOutParamVal = cursorId <= 0;
				if (cachedStmnt != null)
				{
					marshalBindValuesHelper.m_bAllInBinds = cachedStmnt.m_bAllInBinds;
					marshalBindValuesHelper.m_bAllOutBinds = cachedStmnt.m_bAllOutBinds;
				}
				if (bBindParamPresent && bindByPositionParamColl != null)
				{
					marshalBindValuesHelper.m_bindDirections = bindDirections;
					marshalBindValuesHelper.m_sqlStmtType = m_sqlStatementType;
					if (m_bindAccessors == null || m_bindAccessors.Length != bindByPositionParamColl.Count)
					{
						m_bindAccessors = new Accessor[num];
					}
					ProcessParameters(bindByPositionParamColl, connectionImpl, cachedParamMetadata, ref bBindMetadataModified, isFromEF && m_sqlStatementType == SqlStatementType.SELECT, ref marshalBindValuesHelper);
				}
				else
				{
					m_bindAccessors = null;
					m_bindDirectionsFromServer = null;
					m_arrayBindCount = 0;
				}
				if (flag && !bBindMetadataModified && cachedStmnt.m_cursorId > 0 && CanUseOptimizeExecute(m_sqlStatementType, m_rowsToFetch, 1L, bsnapshot: false, orclDependencyImpl != null))
				{
					flag5 = true;
				}
				int noOfRowsFetched = 0;
				int result = 0;
				long queryId = 0L;
				DataUnmarshaller dataUnmarshaller = null;
				if (scnFromExecution != null)
				{
					scnFromExecution[0] = 0L;
					scnFromExecution[1] = 0L;
				}
				else
				{
					scnFromExecution = new long[2];
				}
				if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
				{
					CheckForReturningClause(m_pooledCmdText, m_sqlStatementType, sqlInfo, commandType, bindByPositionParamColl, placeHolderCollection, bBindParamPresent, commandText);
				}
				bool bDisableCompressedFetch = m_bHasReturningClause || SqlStatementType.PLSQL == m_sqlStatementType || (cachedStmnt?.m_bDisableCompressedFetch ?? false);
				int num2 = -1;
				try
				{
					num2 = connectionImpl.WaitForConnectionForExecution(m_cancelExecutionEvent);
					m_continueCancel.Set();
					connectionImpl.AddAllPiggyBackRequests();
					TTCExecuteSql executeSqlObject = connectionImpl.ExecuteSqlObject;
					if (flag5)
					{
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
						executeSqlObject.SendReExecuteRequest(connectionImpl, cursorId, 0L, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, 0, ref marshalBindValuesHelper);
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, 0, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB = false;
						result = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB);
					}
					else
					{
						bool parse = !flag || cursorId == 0;
						bool fetch = (flag && cursorId > 0) || m_bHasReturningClause || m_sqlStatementType == SqlStatementType.PLSQL;
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
						executeSqlObject.SendExecuteRequest(connectionImpl, (flag && cursorId > 0) ? null : m_commandTextByteStream, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, null, 0L, parse, execute: true, fetch, define: false, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, longFetchSize, 0, null, ref marshalBindValuesHelper, 0);
						if (marshalBindValuesHelper.m_bindDirections == null && marshalBindValuesHelper.m_paramValueArray != null)
						{
							marshalBindValuesHelper.ResetBindDirections(bindByPositionParamColl.Count);
							marshalBindValuesHelper.m_bAllInBinds = true;
						}
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, 0, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB2 = false;
						result = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB2);
					}
					lock (m_lockCancel)
					{
						m_bServerExecutionComplete = true;
						if (m_executionId >= long.MaxValue)
						{
							m_executionId = 0L;
						}
						else
						{
							m_executionId++;
						}
					}
					if (connectionImpl.m_oracleCommunication.InBreakResetMode())
					{
						connectionImpl.m_marshallingEngine.ProcessReset();
					}
					if (executeSqlObject.m_bSessionTimeZoneUpdated)
					{
						connectionImpl.m_sessionTimeZone = new OracleIntervalDS(executeSqlObject.m_sessionTimeZone);
						executeSqlObject.m_bSessionTimeZoneUpdated = false;
					}
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (m_sqlMetaData != null)
					{
						m_sqlMetaData.pCommandText = m_pooledCmdText;
						if (!flag2)
						{
							metadata = m_sqlMetaData;
						}
					}
					m_bindDirectionsFromServer = marshalBindValuesHelper.m_bindDirections;
					if (orclDependencyImpl != null)
					{
						orclDependencyImpl.m_bIsEnabled = orclDependencyImpl.m_bIsRegistered;
						if (orclDependencyImpl.m_bQueryBasedNTFN && !orclDependencyImpl.m_queryIDList.Contains(queryId))
						{
							lock (orclDependencyImpl.m_syncList)
							{
								if (!orclDependencyImpl.m_queryIDList.Contains(queryId))
								{
									orclDependencyImpl.m_queryIDList.Add(queryId);
								}
							}
						}
					}
					if ((!bIsDefineInSelect.HasValue || bIsDefineInSelect == false) && (m_sqlStatementType == SqlStatementType.DML || m_sqlStatementType == SqlStatementType.SELECT || m_sqlStatementType == SqlStatementType.PLSQL) && !flag && connectionImpl.m_statementCache != null && m_addToStatementCache)
					{
						cachedStmnt = new CachedStatement();
						cachedStmnt.sqlInfo = new SQLInfo
						{
							m_SQLcommandTextByteStream = m_commandTextByteStream,
							m_SQLhasReturningClause = m_bHasReturningClause,
							m_SQLStatementType = m_sqlStatementType
						};
						cachedStmnt.statementdata = metadata;
						cachedStmnt.m_cursorId = cursorId;
						cachedStmnt.m_bindAccessors = m_bindAccessors;
						cachedStmnt.m_bindParamMetadata = marshalBindValuesHelper.m_paramCollInfoArray;
						cachedStmnt.m_scnFromExecution = scnFromExecution;
						cachedStmnt.m_placeHolderCollection = placeHolderCollection;
						cachedStmnt.m_bBindParamPresent = bBindParamPresent;
						cachedStmnt.m_bindDirections = marshalBindValuesHelper.m_bindDirections;
						cachedStmnt.m_bAllInBinds = marshalBindValuesHelper.m_bAllInBinds;
						cachedStmnt.m_bAllOutBinds = marshalBindValuesHelper.m_bAllOutBinds;
						if (cachedStmnt.statementdata != null && enumerable != null)
						{
							foreach (OracleLpStatement item in enumerable)
							{
								item.m_vODPContext = null;
							}
							cachedStmnt.statementdata.parsedStmt = enumerable;
						}
					}
					if (cachedStmnt != null && connectionImpl.m_statementCache != null)
					{
						if (cachedStmnt.m_cursorId == 0)
						{
							cachedStmnt.m_cursorId = cursorId;
						}
						CachedStatement cachedStatement = connectionImpl.m_statementCache.Put(m_pooledCmdText, cachedStmnt);
						if (cachedStatement != null && cachedStatement.m_cursorId > 0)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement.m_cursorId);
						}
					}
					else
					{
						connectionImpl.AddCursorIdToBeClosed(cursorId);
					}
				}
				finally
				{
					m_continueCancel.Reset();
					if (num2 > 0)
					{
						connectionImpl.m_connectionFreeToUseEvent.Set();
					}
					else if (flag)
					{
						CachedStatement cachedStatement2 = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
						if (cachedStatement2 != null)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement2.m_cursorId);
						}
					}
				}
				if (m_bHasReturningClause && bMoreThanOneRowAffectedByDmlWithRetClause)
				{
					throw new OracleException(24369, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24369));
				}
				if (SqlStatementType.DML != m_sqlStatementType)
				{
					result = -1;
				}
				return result;
			}
			catch (Exception ex)
			{
				if (bindByPositionParamColl != null)
				{
					foreach (OracleParameter item2 in bindByPositionParamColl)
					{
						item2.PreBindFree();
					}
				}
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlQuery, ex);
				if (ex is OracleException)
				{
					connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlQuery);
				}
			}
		}

		internal int ExecuteXmlSave(string commandText, OracleParameterCollection paramColl, CommandType commandType, OracleXmlCommandType xmlCommandType, OracleConnectionImpl connectionImpl, int longFetchSize, long clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, OracleConnection connection, out long[] scnFromExecution, out OracleParameterCollection bindByPositionParamColl, ref bool bBindParamPresent, ref OracleXmlSaveProperties xmlSaveProperties, out OracleException exceptionForArrayBindDML, out bool transform, ref OracleLogicalTransaction oracleLogicalTransaction, bool isFromEF = false)
		{
			bool flag = false;
			bool flag2 = false;
			Accessor[] defineAccessors = null;
			ColumnDescribeInfo[] cachedParamMetadata = null;
			CachedStatement cachedStmnt = null;
			SQLMetaData metadata = null;
			SQLInfo sqlInfo = null;
			int cursorId = 0;
			ArrayList arrayList = null;
			bindByPositionParamColl = null;
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			bool? bIsDefineInSelect = null;
			m_sqlMetaData = null;
			scnFromExecution = null;
			int num = 0;
			OracleParameter oracleParameter = null;
			OracleParameter oracleParameter2 = null;
			OracleClob oracleClob = null;
			OracleParameter oracleParameter3 = null;
			OracleParameter oracleParameter4 = null;
			OracleClob oracleClob2 = null;
			IEnumerable<OracleLpStatement> enumerable = null;
			bool flag3 = false;
			transform = false;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlSave);
			}
			if (xmlSaveProperties == null)
			{
				xmlSaveProperties = new OracleXmlSaveProperties();
			}
			if (xmlSaveProperties.Xslt != null && xmlSaveProperties.Xslt.Length != 0)
			{
				transform = true;
			}
			try
			{
				if (m_implicitRSList != null && m_implicitRSList.Count > 0)
				{
					CloseImplicitRefCursors(connectionImpl);
					m_implicitRSList.Clear();
				}
				BindDirection[] bindDirections = null;
				flag2 = (m_sqlMetaData = metadata) != null;
				string parameterName = ":OracleXmlDoc$";
				string parameterName2 = ":OracleResult$";
				string parameterName3 = ":OracleXslDoc$";
				num = 3;
				if (transform)
				{
					num++;
				}
				BuildXmlSaveCommandText(connection, commandText, xmlCommandType, xmlSaveProperties);
				if (connectionImpl.m_statementCache != null && (!connectionImpl.m_marshallingEngine.m_bDRCPConnection || connectionImpl.m_marshallingEngine.m_bDRCPSessionAttached))
				{
					ValidateStatementCacheSize(connectionImpl);
					connectionImpl.m_statementCache.Get(m_pooledCmdText, out cachedStmnt, out metadata, out sqlInfo);
					if (cachedStmnt != null)
					{
						cursorId = cachedStmnt.m_cursorId;
						m_bindAccessors = cachedStmnt.m_bindAccessors;
						cachedParamMetadata = cachedStmnt.m_bindParamMetadata;
						scnFromExecution = cachedStmnt.m_scnFromExecution;
						arrayList = cachedStmnt.m_placeHolderCollection;
						bBindParamPresent = cachedStmnt.m_bBindParamPresent;
						bindDirections = cachedStmnt.m_bindDirections;
						m_bindDirectionsFromServer = cachedStmnt.m_bindDirections;
						enumerable = ((cachedStmnt.statementdata != null) ? cachedStmnt.statementdata.parsedStmt : null);
						flag = true;
					}
				}
				if (sqlInfo != null)
				{
					m_commandTextByteStream = sqlInfo.m_SQLcommandTextByteStream;
					m_sqlStatementType = sqlInfo.m_SQLStatementType;
				}
				else
				{
					switch (commandType)
					{
					case CommandType.StoredProcedure:
						m_sqlStatementType = SqlStatementType.PLSQL;
						break;
					case CommandType.TableDirect:
						m_sqlStatementType = SqlStatementType.SELECT;
						break;
					default:
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
						{
							m_sqlStatementType = GetSqlStatementType(m_pooledCmdText, ref bIsDefineInSelect);
						}
						break;
					}
					m_commandTextByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(m_pooledCmdText, 0, m_pooledCmdText.Length);
				}
				bindByPositionParamColl = new OracleParameterCollection();
				oracleParameter3 = new OracleParameter(":OracleTableName$", OracleDbType.Varchar2);
				oracleParameter3.Direction = ParameterDirection.Input;
				if (xmlSaveProperties.Table == null)
				{
					oracleParameter3.Value = string.Empty;
				}
				else
				{
					oracleParameter3.Value = xmlSaveProperties.Table;
				}
				bindByPositionParamColl.Add(oracleParameter3);
				if (transform)
				{
					if (connection.m_majorVersion == 8 && connection.m_minorVersion == 1 && xmlSaveProperties.Xslt.Length <= 32512)
					{
						oracleParameter4 = new OracleParameter(parameterName3, OracleDbType.Varchar2);
						oracleParameter4.Direction = ParameterDirection.Input;
						oracleParameter4.Value = xmlSaveProperties.Xslt;
						bindByPositionParamColl.Add(oracleParameter4);
					}
					else
					{
						oracleParameter4 = new OracleParameter(parameterName3, OracleDbType.Clob);
						oracleParameter4.Direction = ParameterDirection.Input;
						oracleClob2 = new OracleClob(connection);
						oracleClob2.Append(xmlSaveProperties.Xslt.ToCharArray(), 0, xmlSaveProperties.Xslt.Length);
						oracleParameter4.Value = oracleClob2;
						bindByPositionParamColl.Add(oracleParameter4);
					}
				}
				oracleParameter = new OracleParameter();
				oracleParameter.ParameterName = parameterName2;
				oracleParameter.DbType = DbType.Int32;
				oracleParameter.Direction = ParameterDirection.Output;
				bindByPositionParamColl.Add(oracleParameter);
				if (commandText.Length > 32512)
				{
					oracleParameter2 = new OracleParameter(parameterName, OracleDbType.Clob);
					oracleParameter2.Direction = ParameterDirection.Input;
					oracleClob = new OracleClob(connection);
					oracleClob.Append(commandText.ToCharArray(), 0, commandText.Length);
					oracleParameter2.Value = oracleClob;
					bindByPositionParamColl.Add(oracleParameter2);
				}
				else
				{
					oracleParameter2 = new OracleParameter(parameterName, OracleDbType.Varchar2);
					oracleParameter2.Direction = ParameterDirection.Input;
					oracleParameter2.Value = commandText;
					bindByPositionParamColl.Add(oracleParameter2);
				}
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.SQL, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlSave, m_pooledCmdText);
				}
				bool flag4 = false;
				bool bBindMetadataModified = false;
				TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
				marshalBindValuesHelper.m_bWriteOutParamVal = cursorId <= 0;
				if (cachedStmnt != null)
				{
					marshalBindValuesHelper.m_bAllInBinds = cachedStmnt.m_bAllInBinds;
					marshalBindValuesHelper.m_bAllOutBinds = cachedStmnt.m_bAllOutBinds;
				}
				if (bBindParamPresent && bindByPositionParamColl != null)
				{
					marshalBindValuesHelper.m_bindDirections = bindDirections;
					marshalBindValuesHelper.m_sqlStmtType = m_sqlStatementType;
					if (m_bindAccessors == null || m_bindAccessors.Length != bindByPositionParamColl.Count)
					{
						m_bindAccessors = new Accessor[bindByPositionParamColl.Count];
					}
					ProcessParameters(bindByPositionParamColl, connectionImpl, cachedParamMetadata, ref bBindMetadataModified, isFromEF && m_sqlStatementType == SqlStatementType.SELECT, ref marshalBindValuesHelper);
				}
				else
				{
					m_bindAccessors = null;
					m_bindDirectionsFromServer = null;
					m_arrayBindCount = 0;
				}
				if (flag && !bBindMetadataModified && cachedStmnt.m_cursorId > 0 && CanUseOptimizeExecute(m_sqlStatementType, m_rowsToFetch, 1L, bsnapshot: false, orclDependencyImpl != null))
				{
					flag4 = true;
				}
				int noOfRowsFetched = 0;
				int result = 0;
				long queryId = 0L;
				DataUnmarshaller dataUnmarshaller = null;
				if (scnFromExecution != null)
				{
					scnFromExecution[0] = 0L;
					scnFromExecution[1] = 0L;
				}
				else
				{
					scnFromExecution = new long[2];
				}
				if (ConfigBaseClass.m_bUseLegacyLocalParser || flag3)
				{
					CheckForReturningClause(m_pooledCmdText, m_sqlStatementType, sqlInfo, commandType, bindByPositionParamColl, arrayList, bBindParamPresent, commandText);
				}
				bool bDisableCompressedFetch = m_bHasReturningClause || SqlStatementType.PLSQL == m_sqlStatementType || (cachedStmnt?.m_bDisableCompressedFetch ?? false);
				int num2 = -1;
				try
				{
					num2 = connectionImpl.WaitForConnectionForExecution(m_cancelExecutionEvent);
					m_continueCancel.Set();
					connectionImpl.AddAllPiggyBackRequests();
					TTCExecuteSql executeSqlObject = connectionImpl.ExecuteSqlObject;
					if (flag4)
					{
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
						executeSqlObject.SendReExecuteRequest(connectionImpl, cursorId, 0L, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, 0, ref marshalBindValuesHelper);
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, 0, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB = false;
						result = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB);
					}
					else
					{
						bool parse = !flag || cursorId == 0;
						bool fetch = (flag && cursorId > 0) || m_bHasReturningClause || m_sqlStatementType == SqlStatementType.PLSQL;
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
						executeSqlObject.SendExecuteRequest(connectionImpl, (flag && cursorId > 0) ? null : m_commandTextByteStream, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, null, 0L, parse, execute: true, fetch, define: false, connectionImpl.m_autoCommit, bDisableCompressedFetch, m_sqlStatementType, longFetchSize, 0, null, ref marshalBindValuesHelper, 0);
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, longFetchSize, 0L, 0L, 0L, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, 0, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList);
						exceptionForArrayBindDML = null;
						bool hasMoreRowsInDB2 = false;
						result = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB2);
					}
					lock (m_lockCancel)
					{
						m_bServerExecutionComplete = true;
						if (m_executionId >= long.MaxValue)
						{
							m_executionId = 0L;
						}
						else
						{
							m_executionId++;
						}
					}
					if (connectionImpl.m_oracleCommunication.InBreakResetMode())
					{
						connectionImpl.m_marshallingEngine.ProcessReset();
					}
					if (executeSqlObject.m_bSessionTimeZoneUpdated)
					{
						connectionImpl.m_sessionTimeZone = new OracleIntervalDS(executeSqlObject.m_sessionTimeZone);
						executeSqlObject.m_bSessionTimeZoneUpdated = false;
					}
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (m_sqlMetaData != null)
					{
						m_sqlMetaData.pCommandText = m_pooledCmdText;
						if (!flag2)
						{
							metadata = m_sqlMetaData;
						}
					}
					m_bindDirectionsFromServer = marshalBindValuesHelper.m_bindDirections;
					if (orclDependencyImpl != null)
					{
						orclDependencyImpl.m_bIsEnabled = orclDependencyImpl.m_bIsRegistered;
						if (orclDependencyImpl.m_bQueryBasedNTFN && !orclDependencyImpl.m_queryIDList.Contains(queryId))
						{
							lock (orclDependencyImpl.m_syncList)
							{
								if (!orclDependencyImpl.m_queryIDList.Contains(queryId))
								{
									orclDependencyImpl.m_queryIDList.Add(queryId);
								}
							}
						}
					}
					if ((!bIsDefineInSelect.HasValue || bIsDefineInSelect == false) && (m_sqlStatementType == SqlStatementType.DML || m_sqlStatementType == SqlStatementType.SELECT || m_sqlStatementType == SqlStatementType.PLSQL) && !flag && connectionImpl.m_statementCache != null && m_addToStatementCache)
					{
						cachedStmnt = new CachedStatement();
						cachedStmnt.sqlInfo = new SQLInfo
						{
							m_SQLcommandTextByteStream = m_commandTextByteStream,
							m_SQLhasReturningClause = m_bHasReturningClause,
							m_SQLStatementType = m_sqlStatementType
						};
						cachedStmnt.statementdata = metadata;
						cachedStmnt.m_cursorId = cursorId;
						cachedStmnt.m_bindAccessors = m_bindAccessors;
						cachedStmnt.m_bindParamMetadata = marshalBindValuesHelper.m_paramCollInfoArray;
						cachedStmnt.m_scnFromExecution = scnFromExecution;
						cachedStmnt.m_placeHolderCollection = arrayList;
						cachedStmnt.m_bBindParamPresent = bBindParamPresent;
						cachedStmnt.m_bindDirections = marshalBindValuesHelper.m_bindDirections;
						cachedStmnt.m_bAllInBinds = marshalBindValuesHelper.m_bAllInBinds;
						cachedStmnt.m_bAllOutBinds = marshalBindValuesHelper.m_bAllOutBinds;
						if (cachedStmnt.statementdata != null && enumerable != null)
						{
							foreach (OracleLpStatement item in enumerable)
							{
								item.m_vODPContext = null;
							}
							cachedStmnt.statementdata.parsedStmt = enumerable;
						}
					}
					if (cachedStmnt != null && connectionImpl.m_statementCache != null)
					{
						if (cachedStmnt.m_cursorId == 0)
						{
							cachedStmnt.m_cursorId = cursorId;
						}
						CachedStatement cachedStatement = connectionImpl.m_statementCache.Put(m_pooledCmdText, cachedStmnt);
						if (cachedStatement != null && cachedStatement.m_cursorId > 0)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement.m_cursorId);
						}
					}
					else
					{
						connectionImpl.AddCursorIdToBeClosed(cursorId);
					}
				}
				finally
				{
					m_continueCancel.Reset();
					if (num2 > 0)
					{
						connectionImpl.m_connectionFreeToUseEvent.Set();
					}
					else if (flag)
					{
						CachedStatement cachedStatement2 = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
						if (cachedStatement2 != null)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement2.m_cursorId);
						}
					}
				}
				if (m_bHasReturningClause && bMoreThanOneRowAffectedByDmlWithRetClause)
				{
					throw new OracleException(24369, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24369));
				}
				if (SqlStatementType.DML != m_sqlStatementType)
				{
					result = -1;
				}
				return result;
			}
			catch (Exception ex)
			{
				if (bindByPositionParamColl != null)
				{
					foreach (OracleParameter item2 in bindByPositionParamColl)
					{
						item2.PreBindFree();
					}
				}
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlSave, ex);
				if (ex is OracleException)
				{
					connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteXmlSave);
				}
			}
		}

		internal int ExecuteReader(string commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, ref OracleDataReaderImpl rdrImpl, int longFetchSize, long clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, long[] scnForExecution, out long[] scnFromExecution, out OracleParameterCollection bindByPositionParamColl, ref bool bBindParamPresent, ref long internalInitialLOBFS, long internalInitialJSONFS, out OracleException exceptionForArrayBindDML, OracleConnection connection, ref OracleLogicalTransaction oracleLogicalTransaction, IEnumerable<OracleLpStatement> adrianParsedStmt, bool isDescribeOnly = false, bool isFromEF = false)
		{
			bool flag = false;
			bool flag2 = false;
			Accessor[] defineAccessors = null;
			ColumnDescribeInfo[] cachedParamMetadata = null;
			List<object> oraBufReleaseInfoList = null;
			CachedStatement cachedStmnt = null;
			SQLMetaData metadata = null;
			SQLInfo sqlInfo = null;
			int cursorId = 0;
			bool flag3 = false;
			ArrayList placeHolderCollection = null;
			DataUnmarshaller dataUnmarshaller = null;
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			bool? bIsDefineInSelect = false;
			string cmdText = commandText;
			bool flag4 = false;
			
			scnFromExecution = null;
			bindByPositionParamColl = null;
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteReader);
			}
			try
			{
				if (m_implicitRSList != null && m_implicitRSList.Count > 0)
				{
					CloseImplicitRefCursors(connectionImpl);
					m_implicitRSList.Clear();
				}
				BindDirection[] bindDirections = null;
				if (connectionImpl.m_statementCache != null && (!connectionImpl.m_marshallingEngine.m_bDRCPConnection || connectionImpl.m_marshallingEngine.m_bDRCPSessionAttached))
				{
					ValidateStatementCacheSize(connectionImpl);
					connectionImpl.m_statementCache.Get(commandText, out cachedStmnt, out metadata, out sqlInfo);
					if (cachedStmnt != null)
					{
						cursorId = cachedStmnt.m_cursorId;
						defineAccessors = cachedStmnt.m_accessors;
						m_bindAccessors = cachedStmnt.m_bindAccessors;
						cachedParamMetadata = cachedStmnt.m_bindParamMetadata;
						scnFromExecution = cachedStmnt.m_scnFromExecution;
						placeHolderCollection = cachedStmnt.m_placeHolderCollection;
						bBindParamPresent = cachedStmnt.m_bBindParamPresent;
						bindDirections = cachedStmnt.m_bindDirections;
						dataUnmarshaller = cachedStmnt.m_dataUnmarshaller;
						m_bindDirectionsFromServer = cachedStmnt.m_bindDirections;
						if (adrianParsedStmt == null)
						{
							adrianParsedStmt = ((cachedStmnt.statementdata != null) ? cachedStmnt.statementdata.parsedStmt : null);
						}
						flag = true;
					}
				}
				if (sqlInfo != null)
				{
					m_commandTextByteStream = sqlInfo.m_SQLcommandTextByteStream;
					m_sqlStatementType = sqlInfo.m_SQLStatementType;
				}
				else
				{
					switch (commandType)
					{
					case CommandType.StoredProcedure:
						m_sqlStatementType = SqlStatementType.PLSQL;
						break;
					case CommandType.TableDirect:
						m_sqlStatementType = SqlStatementType.SELECT;
						break;
					default:
						TrimCommentsFromSQL(ref cmdText);
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag4)
						{
							m_sqlStatementType = GetSqlStatementType(cmdText, ref bIsDefineInSelect);
						}
						break;
					}
					string text = commandText;
					if (!connectionImpl.m_isDb11gR1OrHigher && (m_sqlStatementType == SqlStatementType.PLSQL || cmdText.StartsWith("create", StringComparison.InvariantCultureIgnoreCase)))
					{
						text = commandText.Replace("\r\n", "\n");
					}
					m_commandTextByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(text, 0, text.Length);
				}
				flag2 = (m_sqlMetaData = metadata) != null;
				if (flag2)
				{
					if (m_sqlStatementType == SqlStatementType.SELECT && (m_sqlMetaData.m_maxRowSize > 0 || m_sqlMetaData.m_bHasLOBOrLongColumn || m_sqlMetaData.m_bHasBFILEColumn || m_sqlMetaData.HasJSONColumn))
					{
						int num = m_sqlMetaData.m_maxRowSize + m_sqlMetaData.m_numOfLOBColumns * Math.Max(86, 86 + (int)clientInitialLOBFS) + m_sqlMetaData.m_numOfJSONColumns * Math.Max(86, 86) + m_sqlMetaData.m_numOfLONGColumns * Math.Max(2, longFetchSize) + m_sqlMetaData.m_numOfBFileColumns * 86;
						m_rowsToFetch = (int)m_fetchSize / num;
						m_rowsToFetch++;
						if (m_rowsToFetch > 65535)
						{
							m_rowsToFetch = 65535;
						}
					}
					else
					{
						m_rowsToFetch = 25;
					}
					if (longFetchSize > 0 && m_sqlMetaData.IsInitialLongFetchSizeInChars)
					{
						long num2 = longFetchSize * connectionImpl.m_marshallingEngine.m_dbCharSetConv.MaxBytesPerChar;
						longFetchSize = (int)((num2 >= int.MaxValue) ? int.MaxValue : num2);
					}
				}
				else
				{
					m_rowsToFetch = 25;
				}
				if (isDescribeOnly)
				{
					m_rowsToFetch = 0;
				}
				if (!flag || (bBindParamPresent && m_bBindByName && placeHolderCollection == null))
				{
					if (m_bBindByName)
					{
						placeHolderCollection = new ArrayList();
					}
					switch (commandType)
					{
					case CommandType.Text:
						if (ConfigBaseClass.m_bUseLegacyLocalParser || flag4)
						{
							ParseCommandText(cmdText, ref bBindParamPresent, ref placeHolderCollection);
						}
						break;
					case CommandType.TableDirect:
						bBindParamPresent = false;
						break;
					}
				}
				if (m_bBindByName && paramColl != null && paramColl.Count > 0)
				{
					if (commandType == CommandType.StoredProcedure)
					{
						bindByPositionParamColl = ReorderBindByNameBasedParameterCollectionForStoredProcedure(paramColl);
					}
					else
					{
						bindByPositionParamColl = GetBindByPositionBasedParameterCollection(paramColl, placeHolderCollection);
					}
				}
				else
				{
					bindByPositionParamColl = paramColl;
				}
				bool bLOBArrayFetchRequired = false;
				bool flag5 = false;
				bool bBindMetadataModified = false;
				TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
				marshalBindValuesHelper.m_bWriteOutParamVal = cursorId <= 0;
				if (cachedStmnt != null)
				{
					marshalBindValuesHelper.m_bAllInBinds = cachedStmnt.m_bAllInBinds;
					marshalBindValuesHelper.m_bAllOutBinds = cachedStmnt.m_bAllOutBinds;
				}
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.SQL, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteReader, commandText);
				}
				if (bBindParamPresent && bindByPositionParamColl != null)
				{
					marshalBindValuesHelper.m_bindDirections = bindDirections;
					marshalBindValuesHelper.m_sqlStmtType = m_sqlStatementType;
					if (m_bindAccessors == null || m_bindAccessors.Length != paramColl.Count)
					{
						m_bindAccessors = new Accessor[paramColl.Count];
					}
					ProcessParameters(bindByPositionParamColl, connectionImpl, cachedParamMetadata, ref bBindMetadataModified, isFromEF && m_sqlStatementType == SqlStatementType.SELECT, ref marshalBindValuesHelper);
				}
				else
				{
					m_bindAccessors = null;
					m_bindDirectionsFromServer = null;
					m_arrayBindCount = 0;
				}
				if (m_sqlMetaData != null && m_sqlMetaData.HasLOBOrLongColumn && connectionImpl.m_marshallingEngine.DBVersion >= 11100)
				{
					internalInitialLOBFS = TTCExecuteSql.CalculateInternalILFS(clientInitialLOBFS, m_bExecutingForFill, m_bReturnPSTypes);
					if ((!m_bExecutingForFill && -1 == clientInitialLOBFS) || (m_bExecutingForFill && !m_bReturnPSTypes))
					{
						bLOBArrayFetchRequired = true;
					}
				}
				if (flag && m_sqlMetaData != null && cachedStmnt.m_cursorId > 0 && m_sqlMetaData.bGotDescribeInfoFromDB && (!m_sqlMetaData.HasLOBOrLongColumn || ((cachedStmnt.m_bDefinesDone || connectionImpl.m_marshallingEngine.DBVersion < 11100) && cachedStmnt.m_internalInitialLOBFS == internalInitialLOBFS && cachedStmnt.m_clientInitialLOBFS == clientInitialLOBFS && cachedStmnt.m_longFetchSize == longFetchSize)) && !bBindMetadataModified && CanUseOptimizeExecute(m_sqlStatementType, m_rowsToFetch, (m_arrayBindCount == 0) ? 1 : m_arrayBindCount, bsnapshot: false, orclDependencyImpl != null))
				{
					flag5 = true;
				}
				int noOfRowsFetched = 0;
				bool hasMoreRowsInDB = true;
				int num3 = 0;
				long queryId = 0L;
				if (scnFromExecution != null)
				{
					scnFromExecution[0] = 0L;
					scnFromExecution[1] = 0L;
				}
				else
				{
					scnFromExecution = new long[2];
				}
				if (ConfigBaseClass.m_bUseLegacyLocalParser || flag4)
				{
					CheckForReturningClause(cmdText, m_sqlStatementType, sqlInfo, commandType, bindByPositionParamColl, placeHolderCollection, bBindParamPresent, commandText);
				}
				flag3 = m_bHasReturningClause || SqlStatementType.PLSQL == m_sqlStatementType || (cachedStmnt?.m_bDisableCompressedFetch ?? false);
				int num4 = -1;
				try
				{
					num4 = connectionImpl.WaitForConnectionForExecution(m_cancelExecutionEvent);
					m_continueCancel.Set();
					connectionImpl.AddAllPiggyBackRequests();
					TTCExecuteSql executeSqlObject = connectionImpl.ExecuteSqlObject;
					if (flag5)
					{
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
                        if (marshalBindValuesHelper.m_paramValueArray != null)
                        {

                        }
						executeSqlObject.SendReExecuteRequest(connectionImpl, cursorId, m_rowsToFetch, connectionImpl.m_autoCommit, flag3, m_sqlStatementType, m_arrayBindCount, ref marshalBindValuesHelper);
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, cachedStmnt?.m_numRowsFetchArrayCanAccomodate ?? (-1), (m_sqlStatementType == SqlStatementType.SELECT) ? m_rowsToFetch : 0, out noOfRowsFetched, ref queryId, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList, bLOBArrayFetchRequired);
						exceptionForArrayBindDML = null;
						num3 = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB);
					}
					else
					{
						bool bThrowArrayBindRelatedErrors = true;
						bool parse = !flag || cursorId == 0;
						bool flag6 = false;
						ColumnDescribeInfo[] columnDefines = null;
						if (cachedStmnt != null)
						{
							if ((!cachedStmnt.m_bDefinesDone || cachedStmnt.m_internalInitialLOBFS != internalInitialLOBFS || cachedStmnt.m_clientInitialLOBFS != clientInitialLOBFS) && m_sqlMetaData != null && (m_sqlMetaData.HasLOBOrLongColumn || m_sqlMetaData.HasJSONColumn) && connectionImpl.m_marshallingEngine.DBVersion >= 11100)
							{
								flag6 = true;
								columnDefines = TTCExecuteSql.InitDefines(m_sqlMetaData.m_columnDescribeInfo, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS);
								cachedStmnt.m_internalInitialLOBFS = internalInitialLOBFS;
								cachedStmnt.m_clientInitialLOBFS = clientInitialLOBFS;
								cachedStmnt.m_bDefinesDone = true;
							}
							cachedStmnt.m_longFetchSize = longFetchSize;
						}
						bool fetch = (flag && cursorId > 0 && !flag6) || m_bHasReturningClause || m_sqlStatementType == SqlStatementType.PLSQL;
						bool num5 = m_arrayBindCount > 1 && SqlStatementType.PLSQL == m_sqlStatementType;
						bool flag7 = false;
						if (num5 && (!flag || (flag && !cachedStmnt.m_bAllInBinds && !cachedStmnt.m_bAllOutBinds)))
						{
							flag7 = true;
						}
						oracleLogicalTransaction = connection.OracleLogicalTransaction;
						executeSqlObject.SendExecuteRequest(connectionImpl, (flag && cursorId > 0) ? null : m_commandTextByteStream, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, columnDefines, m_rowsToFetch, parse, execute: true, fetch, flag6, !flag7 && connectionImpl.m_autoCommit, flag3, m_sqlStatementType, longFetchSize, flag7 ? 1 : m_arrayBindCount, scnForExecution, ref marshalBindValuesHelper, 0);
						if (marshalBindValuesHelper.m_bindDirections == null && marshalBindValuesHelper.m_paramValueArray != null)
						{
							marshalBindValuesHelper.ResetBindDirections(paramColl.Count);
							marshalBindValuesHelper.m_bAllInBinds = true;
						}
						executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, cachedStmnt?.m_numRowsFetchArrayCanAccomodate ?? (-1), (m_sqlStatementType == SqlStatementType.SELECT) ? m_rowsToFetch : 0, out noOfRowsFetched, ref queryId, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList, bLOBArrayFetchRequired);
						if (flag7)
						{
							bThrowArrayBindRelatedErrors = false;
						}
						exceptionForArrayBindDML = null;
						num3 = VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors, ref exceptionForArrayBindDML, out hasMoreRowsInDB);
						if (flag7)
						{
							if (marshalBindValuesHelper.m_bAllInBinds || marshalBindValuesHelper.m_bAllOutBinds)
							{
								oracleLogicalTransaction = connection.OracleLogicalTransaction;
								executeSqlObject.SendExecuteRequest(connectionImpl, null, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, columnDefines, m_rowsToFetch, parse: false, execute: true, fetch, define: false, connectionImpl.m_autoCommit, flag3, m_sqlStatementType, longFetchSize, m_arrayBindCount - 1, scnForExecution, ref marshalBindValuesHelper, 1);
								executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, cachedStmnt?.m_numRowsFetchArrayCanAccomodate ?? (-1), (m_sqlStatementType == SqlStatementType.SELECT) ? m_rowsToFetch : 0, out noOfRowsFetched, ref queryId, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount - 1, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList, bLOBArrayFetchRequired);
								num3 += VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB, bFirstIterationDone: true);
							}
							else
							{
								bool bAutoCommit = false;
								for (int i = 1; i < m_arrayBindCount; i++)
								{
									if (i == m_arrayBindCount - 1)
									{
										bAutoCommit = connectionImpl.m_autoCommit;
									}
									oracleLogicalTransaction = connection.OracleLogicalTransaction;
									executeSqlObject.SendExecuteRequest(connectionImpl, null, m_bHasReturningClause, cursorId, (flag && m_sqlMetaData != null && cursorId == 0) ? m_sqlMetaData.m_describeInfoHash : null, orclDependencyImpl?.m_RegIdFromServer ?? 0, columnDefines, m_rowsToFetch, parse: false, execute: true, fetch, define: false, bAutoCommit, flag3, m_sqlStatementType, longFetchSize, 1, scnForExecution, ref marshalBindValuesHelper, i);
									executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref m_sqlMetaData, m_sqlStatementType, cachedStmnt?.m_numRowsFetchArrayCanAccomodate ?? (-1), (m_sqlStatementType == SqlStatementType.SELECT) ? m_rowsToFetch : 0, out noOfRowsFetched, ref queryId, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, cachedStmnt?.m_bDefinesDone ?? false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref m_implicitRSList, bLOBArrayFetchRequired);
									num3 += VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB, bFirstIterationDone: true);
								}
							}
						}
					}
					lock (m_lockCancel)
					{
						m_bServerExecutionComplete = true;
						if (m_executionId >= long.MaxValue)
						{
							m_executionId = 0L;
						}
						else
						{
							m_executionId++;
						}
					}
					if (connectionImpl.m_oracleCommunication.InBreakResetMode())
					{
						connectionImpl.m_marshallingEngine.ProcessReset();
					}
					flag3 = (connectionImpl.m_marshallingEngine.TTCErrorObject.Flags & 0x20) != 0;
					if (cachedStmnt != null)
					{
						cachedStmnt.m_numRowsFetchArrayCanAccomodate = m_rowsToFetch;
						cachedStmnt.m_bDisableCompressedFetch = flag3;
					}
					if (m_sqlMetaData != null && m_sqlMetaData.m_maxRowSize == 0)
					{
						m_sqlMetaData.CalculateRowSize();
					}
					if (orclDependencyImpl != null)
					{
						orclDependencyImpl.m_bIsEnabled = orclDependencyImpl.m_bIsRegistered;
						if (orclDependencyImpl.m_bQueryBasedNTFN && !orclDependencyImpl.m_queryIDList.Contains(queryId))
						{
							lock (orclDependencyImpl.m_syncList)
							{
								if (!orclDependencyImpl.m_queryIDList.Contains(queryId))
								{
									orclDependencyImpl.m_queryIDList.Add(queryId);
								}
							}
						}
					}
					if (executeSqlObject.m_bSessionTimeZoneUpdated)
					{
						connectionImpl.m_sessionTimeZone = new OracleIntervalDS(executeSqlObject.m_sessionTimeZone);
						executeSqlObject.m_bSessionTimeZoneUpdated = false;
					}
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (m_sqlMetaData != null)
					{
						m_sqlMetaData.pCommandText = commandText;
						if (!flag2)
						{
							if (m_sqlStatementType == SqlStatementType.SELECT && (m_sqlMetaData.m_maxRowSize > 0 || m_sqlMetaData.m_bHasLOBOrLongColumn || m_sqlMetaData.m_bHasBFILEColumn || m_sqlMetaData.HasJSONColumn))
							{
								int num6 = m_sqlMetaData.m_maxRowSize + m_sqlMetaData.m_numOfLOBColumns * Math.Max(86, 86 + (int)clientInitialLOBFS) + m_sqlMetaData.m_numOfJSONColumns * Math.Max(86, 86) + m_sqlMetaData.m_numOfLONGColumns * Math.Max(2, longFetchSize) + m_sqlMetaData.m_numOfBFileColumns * 86;
								m_rowsToFetch = (int)m_fetchSize / num6;
								m_rowsToFetch++;
								if (m_rowsToFetch > 65535)
								{
									m_rowsToFetch = 65535;
								}
							}
							metadata = m_sqlMetaData;
						}
					}
					m_bindDirectionsFromServer = marshalBindValuesHelper.m_bindDirections;
					if (exceptionForArrayBindDML != null)
					{
						return num3;
					}
					if ((!bIsDefineInSelect.HasValue || bIsDefineInSelect == false) && (m_sqlStatementType == SqlStatementType.DML || m_sqlStatementType == SqlStatementType.SELECT || m_sqlStatementType == SqlStatementType.PLSQL) && !flag && connectionImpl.m_statementCache != null && m_addToStatementCache)
					{
						cachedStmnt = new CachedStatement();
						cachedStmnt.sqlInfo = new SQLInfo
						{
							m_SQLcommandTextByteStream = m_commandTextByteStream,
							m_SQLhasReturningClause = m_bHasReturningClause,
							m_SQLStatementType = m_sqlStatementType
						};
						cachedStmnt.statementdata = metadata;
						cachedStmnt.m_cursorId = cursorId;
						cachedStmnt.m_bDisableCompressedFetch = flag3;
						cachedStmnt.m_accessors = defineAccessors;
						cachedStmnt.m_numRowsFetchArrayCanAccomodate = m_rowsToFetch;
						cachedStmnt.m_bindAccessors = m_bindAccessors;
						cachedStmnt.m_bindParamMetadata = marshalBindValuesHelper.m_paramCollInfoArray;
						cachedStmnt.m_scnFromExecution = scnFromExecution;
						cachedStmnt.m_placeHolderCollection = placeHolderCollection;
						cachedStmnt.m_bBindParamPresent = bBindParamPresent;
						cachedStmnt.m_dataUnmarshaller = dataUnmarshaller;
						cachedStmnt.m_bindDirections = marshalBindValuesHelper.m_bindDirections;
						cachedStmnt.m_bAllInBinds = marshalBindValuesHelper.m_bAllInBinds;
						cachedStmnt.m_bAllOutBinds = marshalBindValuesHelper.m_bAllOutBinds;
						if (cachedStmnt.statementdata != null && adrianParsedStmt != null)
						{
							foreach (OracleLpStatement item in adrianParsedStmt)
							{
								item.m_vODPContext = null;
							}
							cachedStmnt.statementdata.parsedStmt = adrianParsedStmt;
						}
					}
				}
				finally
				{
					m_continueCancel.Reset();
					if (num4 > 0)
					{
						connectionImpl.m_connectionFreeToUseEvent.Set();
					}
					else if (flag)
					{
						CachedStatement cachedStatement = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
						if (cachedStatement != null)
						{
							connectionImpl.AddCursorIdToBeClosed(cachedStatement.m_cursorId);
						}
					}
				}
				if (m_bHasReturningClause && bMoreThanOneRowAffectedByDmlWithRetClause)
				{
					throw new OracleException(24369, string.Empty, string.Empty, OracleStringResourceManager.GetErrorMesg(24369));
				}
				if (cachedStmnt != null)
				{
					_ = connectionImpl.m_statementCache;
				}
				if (m_sqlStatementType == SqlStatementType.SELECT)
				{
					bool bInitialLongFetchSizeModified = false;
					if (!flag)
					{
						if (m_sqlMetaData != null && longFetchSize > 0 && m_sqlMetaData.IsInitialLongFetchSizeInChars)
						{
							long num7 = longFetchSize * connectionImpl.m_marshallingEngine.m_dbCharSetConv.MaxBytesPerChar;
							longFetchSize = (int)((num7 >= int.MaxValue) ? int.MaxValue : num7);
							bInitialLongFetchSizeModified = true;
						}
						if (cachedStmnt != null)
						{
							cachedStmnt.m_longFetchSize = longFetchSize;
						}
					}
					rdrImpl = connectionImpl.GetInitializedDataReaderImpl(defineAccessors, m_sqlMetaData, cursorId, noOfRowsFetched, cachedStmnt, m_sessionTimeZone, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, m_addRowidDoneImplicitly, bInitialLongFetchSizeModified);
					if (dataUnmarshaller != null)
					{
						rdrImpl.m_dataUnmarshaller = dataUnmarshaller;
						if (rdrImpl.m_dataUnmarshaller.m_charArrayForConversion == null)
						{
							rdrImpl.m_dataUnmarshaller.m_charArrayForConversion = connectionImpl.m_marshallingEngine.m_charArrayPooler.Dequeue();
						}
					}
					rdrImpl.m_bHasMoreRowsInDB = hasMoreRowsInDB;
					rdrImpl.m_oraBufReleaseInfoList = oraBufReleaseInfoList;
				}
				else if (cachedStmnt != null && connectionImpl.m_statementCache != null)
				{
					if (cachedStmnt.m_cursorId == 0)
					{
						cachedStmnt.m_cursorId = cursorId;
					}
					CachedStatement cachedStatement2 = connectionImpl.m_statementCache.Put(commandText, cachedStmnt);
					if (cachedStatement2 != null && cachedStatement2.m_cursorId > 0)
					{
						connectionImpl.AddCursorIdToBeClosed(cachedStatement2.m_cursorId);
					}
				}
				else
				{
					connectionImpl.AddCursorIdToBeClosed(cursorId);
				}
				return num3;
			}
			catch (Exception ex)
			{
				if (bindByPositionParamColl != null)
				{
					foreach (OracleParameter item2 in bindByPositionParamColl)
					{
						item2.PreBindFree();
					}
				}
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteReader, ex);
				if (ex is OracleException)
				{
					connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExecuteReader);
				}
			}
		}

		internal OracleDataReaderImpl GetReaderImplWithSchemaOnly(OracleConnectionImpl connectionImpl, CommandType commandType, string commandText, bool? gotSqlMetadata, SQLMetaData sqlMetaData)
		{
			SQLInfo info = null;
			int cursorId = 0;
			m_sqlMetaData = sqlMetaData;
			if (!gotSqlMetadata.HasValue)
			{
				gotSqlMetadata = ((connectionImpl.m_statementCache != null && connectionImpl.m_statementCache.PeekForSQLMetaInfo(commandText, out info, out m_sqlMetaData) && m_sqlMetaData.bGotDescribeInfoFromDB) ? new bool?(true) : new bool?(false));
			}
			if (gotSqlMetadata == false)
			{
				m_commandTextByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(commandText, 0, commandText.Length);
				m_sqlMetaData = new SQLMetaData();
				try
				{
					connectionImpl.WaitForConnectionForExecution();
					TTCDescribe tTCDescribe = new TTCDescribe(connectionImpl.m_marshallingEngine);
					tTCDescribe.WriteMessage(m_commandTextByteStream);
					tTCDescribe.ReadMessage(m_sqlMetaData);
					bool hasMoreRowsInDB = false;
					OracleException exceptionForArrayBindDML = null;
					VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB, bFirstIterationDone: true);
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (m_sqlMetaData != null)
					{
						m_sqlMetaData.pCommandText = commandText;
					}
				}
				finally
				{
					connectionImpl.m_connectionFreeToUseEvent.Set();
				}
			}
			return connectionImpl.GetInitializedDataReaderImpl(null, m_sqlMetaData, cursorId, 0, null, m_sessionTimeZone, 0L, 0L, 0L, 0L, null, m_addRowidDoneImplicitly);
		}

		private void ProcessParameters(OracleParameterCollection paramColl, OracleConnectionImpl connectionImpl, ColumnDescribeInfo[] cachedParamMetadata, ref bool bBindMetadataModified, bool isEFSelectStatement, ref TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ProcessParameters);
			}
			try
			{
				InitializeParamInfo(paramColl, connectionImpl, cachedParamMetadata, ref bBindMetadataModified, isEFSelectStatement, ref marshalBindValuesHelper);
				BindDirection[] bindDirections = marshalBindValuesHelper.m_bindDirections;
				ColumnDescribeInfo[] paramCollInfoArray = marshalBindValuesHelper.m_paramCollInfoArray;
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Prm, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ProcessParameters, "Parameters Count = " + paramColl.Count);
				}
				int num = 0;
				int num2 = 0;
				foreach (OracleParameter item in paramColl)
				{
					if (item.m_bDuplicateBind)
					{
						num++;
						continue;
					}
					if (bindDirections != null && bindDirections[num2] == BindDirection.Input)
					{
						num++;
						num2++;
						continue;
					}
					if (item.CollectionType == OracleCollectionType.PLSQLAssociativeArray)
					{
						if ((m_bindAccessors[num2] == null) | bBindMetadataModified)
						{
							m_bindAccessors[num2] = new TTCPLSQLAssociativeArrayAccessor(paramCollInfoArray[num], connectionImpl.m_marshallingEngine);
						}
						else
						{
							m_bindAccessors[num2].Initialize(paramCollInfoArray[num], connectionImpl.m_marshallingEngine, bForBind: true);
						}
					}
					else
					{
						if ((m_bindAccessors[num2] == null) | bBindMetadataModified)
						{
							m_bindAccessors[num2] = Accessor.CreateAccessorForBind(connectionImpl.m_marshallingEngine, paramCollInfoArray[num], m_sqlStatementType, 0, 33554432L, m_arrayBindCount);
						}
						else
						{
							m_bindAccessors[num2].Initialize(paramCollInfoArray[num], connectionImpl.m_marshallingEngine, bForBind: true);
							m_bindAccessors[num2].m_statementType = m_sqlStatementType;
						}
						if (m_bHasReturningClause)
						{
							m_bindAccessors[num2].m_bForReturningParameter = true;
						}
					}
					if (ProviderConfig.m_bTraceLevelPublic)
					{
						string text = item.m_paramName;
						if (string.IsNullOrEmpty(text))
						{
							text = (num + 1).ToString();
						}
						StringBuilder stringBuilder = new StringBuilder();
						stringBuilder.Append("(Name/Position = " + text + ") ");
						stringBuilder.Append("(OracleDbType = " + item.OracleDbType.ToString() + ") ");
						stringBuilder.Append("(Direction = " + item.Direction.ToString() + ") ");
						stringBuilder.Append("(Size (In Bytes) = " + item.m_maxBytesToBeWrittenOrRead + ") ");
						stringBuilder.Append("(Array Bind Count = " + item.m_bindElemCnt + ") ");
						if (item.m_oraDbType == OracleDbType.Decimal)
						{
							stringBuilder.Append("(Precision = " + item.Precision + ") ");
							stringBuilder.Append("(Scale = " + item.Scale + ") ");
						}
						Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Prm, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ProcessParameters, stringBuilder.ToString());
					}
					num++;
					num2++;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ProcessParameters, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ProcessParameters);
				}
			}
		}

		private ICollection InitializeParamInfo(ICollection paramColl, OracleConnectionImpl connectionImpl, ColumnDescribeInfo[] cachedParamMetadata, ref bool bMetadataModified, bool isEFSelectStatement, ref TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.InitializeParamInfo);
			}
			ColumnDescribeInfo[] array = null;
			object[] array2 = null;
			object[] array3 = null;
			int num = 0;
			int num2 = 0;
			if (marshalBindValuesHelper.m_indexOfLongParamsWithLargeData != null)
			{
				marshalBindValuesHelper.m_indexOfLongParamsWithLargeData.Clear();
			}
			else
			{
				marshalBindValuesHelper.m_indexOfLongParamsWithLargeData = new List<int>();
			}
			try
			{
				if (paramColl != null && (num2 = paramColl.Count) > 0)
				{
					bool flag = true;
					if (cachedParamMetadata != null)
					{
						if (cachedParamMetadata.Length == num2)
						{
							array = cachedParamMetadata;
							flag = false;
						}
						else
						{
							bMetadataModified = true;
						}
					}
					if (flag)
					{
						array = new ColumnDescribeInfo[num2];
					}
					array2 = new object[num2];
					array3 = new object[num2];
					foreach (OracleParameter item in paramColl)
					{
						item.PreBind(connectionImpl, (cachedParamMetadata != null && cachedParamMetadata.Length > num) ? cachedParamMetadata[num] : null, ref bMetadataModified, m_arrayBindCount, out var paramMetaData, out var paramValue, isEFSelectStatement, m_sqlStatementType);
						array[num] = paramMetaData;
						if (item.Direction == ParameterDirection.Input || item.Direction == ParameterDirection.InputOutput)
						{
							array2[num] = paramValue;
							if (item.m_bArrayBind)
							{
								array3[num] = item.m_paramImpl.m_qLocatorDataForArrayBind;
								item.m_paramImpl.m_qLocatorDataForArrayBind = null;
							}
							else
							{
								array3[num] = item.m_paramImpl.m_qLocatorData;
								item.m_paramImpl.m_qLocatorData = null;
							}
							if (m_sqlStatementType != SqlStatementType.PLSQL)
							{
								long num3 = (connectionImpl.m_b32kTypeSupported ? 32767 : 4000);
								OraType dataType = (OraType)paramMetaData.m_dataType;
								if ((dataType == OraType.ORA_LONG || dataType == OraType.ORA_LONGRAW || dataType == OraType.ORA_CHAR || dataType == OraType.ORA_CHARN || dataType == OraType.ORA_RAW) && paramMetaData.m_maxLength > num3)
								{
									marshalBindValuesHelper.m_indexOfLongParamsWithLargeData.Add(num);
								}
							}
						}
						num++;
					}
				}
				else
				{
					bMetadataModified = false;
				}
				marshalBindValuesHelper.m_paramValueArray = array2;
				marshalBindValuesHelper.m_qLocatorDataArray = array3;
				marshalBindValuesHelper.m_paramCollInfoArray = array;
				return paramColl;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.InitializeParamInfo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.InitializeParamInfo);
				}
			}
		}

		internal static SqlStatementType GetSqlStatementType(string cmdText, ref bool? bIsDefineInSelect)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetSqlStatementType);
			}
			try
			{
				SqlStatementType result;
				if (cmdText.StartsWith("SELECT", StringComparison.InvariantCultureIgnoreCase) || cmdText.StartsWith("WITH", StringComparison.InvariantCultureIgnoreCase))
				{
					result = SqlStatementType.SELECT;
					if (bIsDefineInSelect.HasValue)
					{
						int num = 0;
						int num2 = 0;
						int num3 = 0;
						num = cmdText.IndexOf("select", StringComparison.OrdinalIgnoreCase);
						num2 = cmdText.IndexOf("from", StringComparison.OrdinalIgnoreCase);
						while (num != -1 && num2 != -1)
						{
							num3 = cmdText.IndexOf(':');
							if (num3 > num && num3 < num2)
							{
								bIsDefineInSelect = true;
								break;
							}
							num = cmdText.IndexOf("select", num2 + 3, StringComparison.OrdinalIgnoreCase);
							if (num != -1)
							{
								num2 = cmdText.IndexOf("from", num + 5, StringComparison.OrdinalIgnoreCase);
							}
						}
					}
				}
				else
				{
					result = ((cmdText.StartsWith("INSERT", StringComparison.InvariantCultureIgnoreCase) || cmdText.StartsWith("DELETE", StringComparison.InvariantCultureIgnoreCase) || cmdText.StartsWith("UPDATE", StringComparison.InvariantCultureIgnoreCase) || cmdText.StartsWith("MERGE", StringComparison.InvariantCultureIgnoreCase)) ? SqlStatementType.DML : ((!cmdText.StartsWith("begin", StringComparison.InvariantCultureIgnoreCase) && !cmdText.StartsWith("BEGIN", StringComparison.InvariantCultureIgnoreCase) && !cmdText.StartsWith("declare", StringComparison.InvariantCultureIgnoreCase) && !cmdText.StartsWith("DECLARE", StringComparison.InvariantCultureIgnoreCase)) ? SqlStatementType.OTHERS : SqlStatementType.PLSQL));
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetSqlStatementType, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetSqlStatementType);
				}
			}
		}

		private void CheckForReturningClause(string cmdTextWithoutComments, SqlStatementType statementType, SQLInfo sqlInfo, CommandType commandType, OracleParameterCollection paramCollection, ArrayList placeholderCollection, bool bBindParamPresent, string originalCmdText)
		{
			if (sqlInfo != null)
			{
				m_bHasReturningClause = sqlInfo.m_SQLhasReturningClause;
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CheckForReturningClause, "Cmd Text (From Cache):  HasReturnClauseSearchKey : " + originalCmdText + "\nHas Returning Clause: " + m_bHasReturningClause);
				}
				return;
			}
			switch (commandType)
			{
			case CommandType.StoredProcedure:
				m_bHasReturningClause = false;
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CheckForReturningClause, "Cmd Text (StoredProcedure):  HasReturnClauseSearchKey : " + originalCmdText + "\nHas Returning Clause: " + m_bHasReturningClause);
				}
				break;
			case CommandType.TableDirect:
				m_bHasReturningClause = false;
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CheckForReturningClause, "Cmd Text (TableDirect):  HasReturnClauseSearchKey : " + originalCmdText + "\nHas Returning Clause: " + m_bHasReturningClause);
				}
				break;
			default:
				m_bHasReturningClause = HasReturningClause(cmdTextWithoutComments, statementType, paramCollection, placeholderCollection, bBindParamPresent);
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.CheckForReturningClause, "Cmd Text (SQL):  HasReturnClauseSearchKey : " + originalCmdText + "\nHas Returning Clause: " + m_bHasReturningClause);
				}
				break;
			}
		}

		private static bool HasReturningClause(string cmdText, SqlStatementType stmtType, OracleParameterCollection paramCollection, ArrayList placeholderCollection, bool bBindParamPresent)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.HasReturningClause);
			}
			try
			{
				bool result = false;
				if (SqlStatementType.PLSQL == stmtType || cmdText == null)
				{
					result = false;
				}
				else
				{
					try
					{
						if ((paramCollection != null && paramCollection.Count != 0) || (placeholderCollection != null && placeholderCollection.Count != 0) || bBindParamPresent)
						{
							Regex regex = new Regex("(?i)\\s+(RETURN|RETURNING)\\s+.+\\s+INTO\\s+:+");
							string text = cmdText;
							if (text.Contains("\n"))
							{
								text = text.Replace("\r\n", " ");
								text = text.Replace("\n", " ");
							}
							MatchCollection matchCollection = regex.Matches(text);
							if (matchCollection.Count != 0)
							{
								Match match = matchCollection[matchCollection.Count - 1];
								if (text.IndexOf('\'', match.Index + match.Length) == -1)
								{
									result = true;
								}
							}
						}
					}
					catch
					{
						if (ProviderConfig.m_bTraceLevelPublic)
						{
							Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.HasReturningClause, "Error while trying to search for returning clause. Trying another search pattern");
						}
						result = Regex.IsMatch(cmdText, "\\bRETURNING\\b | \\bRETURN\\b ", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.HasReturningClause, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.HasReturningClause);
				}
			}
		}

		internal void ExtractAccessorValuesIntoParam(OracleParameterCollection paramColl, OracleConnection connection, int paramCount, string commandText, long longFetchSize, long clientInitialLOBFS, long internalInitialLOBFS, long internalInitialJSONFS, long[] scnFromExecution, bool bCallFromExecuteReader)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractAccessorValuesIntoParam);
			}
			int num = 0;
			Accessor accessor = null;
			char[] array = null;
			try
			{
				for (int i = 0; i < paramCount; i++)
				{
					OracleParameter oracleParameter = paramColl[i];
					if (oracleParameter.OracleDbType == OracleDbType.RefCursor)
					{
						if (m_bBindByName)
						{
							oracleParameter.m_paramPosOrName = oracleParameter.ParameterName;
						}
						else
						{
							oracleParameter.m_paramPosOrName = i.ToString();
						}
					}
					if (oracleParameter.m_bDuplicateBind)
					{
						continue;
					}
					if (m_bindDirectionsFromServer[num] != BindDirection.Input)
					{
						accessor = m_bindAccessors[num];
						if (m_bHasReturningClause && ParameterDirection.InputOutput == oracleParameter.m_direction && !accessor.m_bReceivedOutValueFromServer)
						{
							num++;
							continue;
						}
						switch (oracleParameter.OracleDbType)
						{
						case OracleDbType.Char:
						case OracleDbType.Long:
						case OracleDbType.NChar:
						case OracleDbType.NVarchar2:
						case OracleDbType.Varchar2:
							if (array == null)
							{
								array = connection.m_oracleConnectionImpl.m_marshallingEngine.m_charArrayPooler.Dequeue();
							}
							oracleParameter.PostBind_Char(connection.m_oracleConnectionImpl, accessor, array);
							break;
						case OracleDbType.Decimal:
							oracleParameter.PostBind_Decimal(accessor);
							break;
						case OracleDbType.Byte:
						case OracleDbType.Int16:
						case OracleDbType.Int32:
							oracleParameter.PostBind_Int32(accessor);
							break;
						case OracleDbType.Boolean:
							oracleParameter.PostBind_Boolean(accessor);
							break;
						case OracleDbType.Int64:
							oracleParameter.PostBind_Int64(accessor);
							break;
						case OracleDbType.RefCursor:
							oracleParameter.PostBind_RefCursor(connection, accessor, m_fetchSize, m_sessionTimeZone, commandText, oracleParameter.m_paramPosOrName, longFetchSize, clientInitialLOBFS, internalInitialLOBFS, internalInitialJSONFS, scnFromExecution, bCallFromExecuteReader);
							break;
						case OracleDbType.Date:
							oracleParameter.PostBind_Date(accessor);
							break;
						case OracleDbType.BFile:
						case OracleDbType.Blob:
						case OracleDbType.Clob:
						case OracleDbType.NClob:
							oracleParameter.PostBind_Lob(connection, accessor);
							break;
						case OracleDbType.Json:
							oracleParameter.PostBind_Json(connection, accessor);
							break;
						case OracleDbType.IntervalDS:
							oracleParameter.PostBind_IntervalDS(m_bindAccessors[num]);
							break;
						case OracleDbType.IntervalYM:
							oracleParameter.PostBind_IntervalYM(accessor);
							break;
						case OracleDbType.TimeStamp:
							oracleParameter.PostBind_TimeStamp(accessor);
							break;
						case OracleDbType.TimeStampLTZ:
							oracleParameter.PostBind_TimeStampLTZ(connection.m_oracleConnectionImpl, accessor);
							break;
						case OracleDbType.TimeStampTZ:
							oracleParameter.PostBind_TimeStampTZ(connection.m_oracleConnectionImpl, accessor);
							break;
						case OracleDbType.Single:
							oracleParameter.PostBind_Single(accessor);
							break;
						case OracleDbType.BinaryFloat:
							oracleParameter.PostBind_BinaryFloat(accessor);
							break;
						case OracleDbType.Double:
							oracleParameter.PostBind_Double(accessor);
							break;
						case OracleDbType.BinaryDouble:
							oracleParameter.PostBind_BinaryDouble(accessor);
							break;
						case OracleDbType.LongRaw:
						case OracleDbType.Raw:
							oracleParameter.PostBind_Raw(accessor);
							break;
						case OracleDbType.XmlType:
							oracleParameter.PostBind_XmlType(connection, accessor);
							break;
						default:
							oracleParameter.Value = accessor.GetValue();
							break;
						}
						accessor.Initialize();
					}
					num++;
				}
				num = 0;
				for (int j = 0; j < paramCount; j++)
				{
					OracleParameter oracleParameter = paramColl[j];
					if (oracleParameter.m_bDuplicateBind)
					{
						continue;
					}
					if (m_bindDirectionsFromServer[num] != BindDirection.Output)
					{
						accessor = m_bindAccessors[num];
						if (m_bHasReturningClause && ParameterDirection.InputOutput == oracleParameter.m_direction && !accessor.m_bReceivedOutValueFromServer)
						{
							num++;
							continue;
						}
						if (m_bindDirectionsFromServer[num] == BindDirection.InputOutput)
						{
							switch (oracleParameter.OracleDbType)
							{
							case OracleDbType.Blob:
								if (oracleParameter.Value == null)
								{
									break;
								}
								if (oracleParameter.Value is OracleBlob)
								{
									if ((oracleParameter.Value as OracleBlob).m_inOutBlobToBeRefRefed != null)
									{
										(oracleParameter.Value as OracleBlob).m_inOutBlobToBeRefRefed.RelRef();
										(oracleParameter.Value as OracleBlob).m_inOutBlobToBeRefRefed = null;
									}
								}
								else
								{
									if (!(oracleParameter.Value is OracleBlob[]))
									{
										break;
									}
									OracleBlob[] array3 = (OracleBlob[])oracleParameter.Value;
									for (int l = 0; l < array3.Length; l++)
									{
										if (array3[l] != null && array3[l].m_inOutBlobToBeRefRefed != null)
										{
											array3[l].m_inOutBlobToBeRefRefed.RelRef();
											array3[l].m_inOutBlobToBeRefRefed = null;
										}
									}
								}
								break;
							case OracleDbType.Clob:
							case OracleDbType.NClob:
								if (oracleParameter.Value == null)
								{
									break;
								}
								if (oracleParameter.Value is OracleClob)
								{
									if ((oracleParameter.Value as OracleClob).m_inOutClobToBeRefRefed != null)
									{
										(oracleParameter.Value as OracleClob).m_inOutClobToBeRefRefed.RelRef();
										(oracleParameter.Value as OracleClob).m_inOutClobToBeRefRefed = null;
									}
								}
								else
								{
									if (!(oracleParameter.Value is OracleClob[]))
									{
										break;
									}
									OracleClob[] array2 = (OracleClob[])oracleParameter.Value;
									for (int k = 0; k < array2.Length; k++)
									{
										if (array2[k] != null && array2[k].m_inOutClobToBeRefRefed != null)
										{
											array2[k].m_inOutClobToBeRefRefed.RelRef();
											array2[k].m_inOutClobToBeRefRefed = null;
										}
									}
								}
								break;
							}
						}
						else if (m_bindDirectionsFromServer[num] == BindDirection.Input)
						{
							OracleDbType oracleDbType = oracleParameter.OracleDbType;
							if (oracleDbType == OracleDbType.Blob || oracleDbType == OracleDbType.Clob || oracleDbType == OracleDbType.NClob)
							{
								oracleParameter.PreBindFree();
							}
						}
					}
					num++;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractAccessorValuesIntoParam, ex);
				throw;
			}
			finally
			{
				if (array != null)
				{
					connection.m_oracleConnectionImpl.m_marshallingEngine.m_charArrayPooler.Enqueue(array);
				}
				if (connection.m_oracleConnectionImpl.m_marshallingEngine.m_oraBufRdr != null)
				{
					connection.m_oracleConnectionImpl.m_marshallingEngine.m_oraBufRdr.FreeTempOBList();
				}
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractAccessorValuesIntoParam);
				}
			}
		}

		internal OracleClob ExtractXMLValuesIntoParam(ref OracleParameterCollection paramColl, OracleConnection connection, int paramIndex, bool wantResult, bool transform, bool isOracle8i, OracleXmlQueryProperties xmlQueryProperties)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLValuesIntoParam);
			}
			Accessor accessor = null;
			char[] array = null;
			OracleParameter oracleParameter = null;
			OracleParameter oracleParameter2 = null;
			OracleParameter oracleParameter3 = null;
			try
			{
				if (transform)
				{
					oracleParameter2 = paramColl[paramIndex];
					paramIndex++;
				}
				if (isOracle8i)
				{
					oracleParameter3 = paramColl[paramIndex];
					paramIndex++;
				}
				if (wantResult)
				{
					oracleParameter = paramColl[paramIndex];
					accessor = m_bindAccessors[paramIndex];
					try
					{
						oracleParameter.PostBind_Lob(connection, accessor);
					}
					catch (Exception)
					{
						oracleParameter.PreBindFree();
						if (transform)
						{
							oracleParameter2 = paramColl[paramIndex];
							paramIndex++;
						}
						if (isOracle8i)
						{
							oracleParameter3 = paramColl[paramIndex];
							paramIndex++;
						}
						throw;
					}
					paramIndex++;
				}
				if (wantResult)
				{
					if (oracleParameter.Value.GetType().FullName!.Equals("Oracle.ManagedDataAccess.Types.OracleClob") && !((OracleClob)oracleParameter.Value).IsNull)
					{
						return (OracleClob)oracleParameter.Value;
					}
					string text = null;
					text = ((!isOracle8i) ? "<?xml version = \"1.0\"?>\n" : "<?xml version = '1.0'?>\n");
					if (xmlQueryProperties.RootTag != null && xmlQueryProperties.RootTag.Length != 0)
					{
						text = text + "<" + xmlQueryProperties.RootTag + "/>\n";
					}
					OracleClob oracleClob = new OracleClob(connection);
					oracleClob.Append(text.ToCharArray(), 0, text.Length);
					return oracleClob;
				}
				return null;
			}
			catch (Exception ex2)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLValuesIntoParam, ex2);
				throw;
			}
			finally
			{
				if (oracleParameter != null)
				{
					paramColl.Remove(oracleParameter);
				}
				if (oracleParameter2 != null)
				{
					paramColl.Remove(oracleParameter2);
				}
				if (oracleParameter3 != null)
				{
					paramColl.Remove(oracleParameter3);
				}
				if (array != null)
				{
					connection.m_oracleConnectionImpl.m_marshallingEngine.m_charArrayPooler.Enqueue(array);
				}
				if (connection.m_oracleConnectionImpl.m_marshallingEngine.m_oraBufRdr != null)
				{
					connection.m_oracleConnectionImpl.m_marshallingEngine.m_oraBufRdr.FreeTempOBList();
				}
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLValuesIntoParam);
				}
			}
		}

		internal int ExtractXMLSaveValuesIntoParam(ref OracleParameterCollection paramColl, bool transform)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLSaveValuesIntoParam);
			}
			int num = 0;
			Accessor accessor = null;
			OracleParameter oracleParameter = null;
			OracleParameter oracleParameter2 = null;
			OracleParameter oracleParameter3 = null;
			OracleParameter oracleParameter4 = null;
			try
			{
				oracleParameter = paramColl[num];
				num++;
				if (transform)
				{
					oracleParameter4 = paramColl[num];
					num++;
				}
				oracleParameter2 = paramColl[num];
				accessor = m_bindAccessors[num];
				try
				{
					oracleParameter2.PostBind_Int32(accessor);
				}
				catch (Exception)
				{
					oracleParameter2.PreBindFree();
					num++;
					throw;
				}
				num++;
				oracleParameter3 = paramColl[num];
				return (int)oracleParameter2.Value;
			}
			catch (Exception ex2)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLSaveValuesIntoParam, ex2);
				throw;
			}
			finally
			{
				if (oracleParameter != null)
				{
					paramColl.Remove(oracleParameter);
				}
				if (oracleParameter2 != null)
				{
					paramColl.Remove(oracleParameter2);
				}
				if (oracleParameter3 != null)
				{
					paramColl.Remove(oracleParameter3);
				}
				if (oracleParameter4 != null)
				{
					paramColl.Remove(oracleParameter4);
				}
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ExtractXMLSaveValuesIntoParam);
				}
			}
		}

		internal void RetrieveMetadata(string commandText, CommandType commandType, OracleParameterCollection paramColl, OracleConnectionImpl connectionImpl, OracleConnection con, out SQLMetaData sqlMetadata, out int hiddenColumnCount)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata);
			}
			sqlMetadata = null;
			hiddenColumnCount = 0;
			if (commandType != CommandType.Text && commandType != CommandType.TableDirect)
			{
				return;
			}
			m_sqlMetaData = null;
			bool flag = false;
			bool? bIsDefineInSelect = false;
			bool bMoreThanOneRowAffectedByDmlWithRetClause = false;
			string cmdText = commandText;
			bool flag2 = false;
			try
			{
				SQLInfo info = null;
				if (connectionImpl.m_statementCache != null && connectionImpl.m_statementCache.PeekForSQLMetaInfo(commandText, out info, out sqlMetadata) && sqlMetadata.bGotDescribeInfoFromDB)
				{
					flag = true;
				}
				if (flag)
				{
					goto IL_03b9;
				}
				if (commandType == CommandType.TableDirect)
				{
					m_sqlStatementType = SqlStatementType.SELECT;
					goto IL_00ba;
				}
				TrimCommentsFromSQL(ref cmdText);
				if (ConfigBaseClass.m_bUseLegacyLocalParser || flag2)
				{
					m_sqlStatementType = GetSqlStatementType(cmdText, ref bIsDefineInSelect);
				}
				if (m_sqlStatementType == SqlStatementType.SELECT)
				{
					goto IL_00ba;
				}
				goto end_IL_004b;
				IL_03b9:
				m_sqlMetaData = sqlMetadata;
				hiddenColumnCount = OracleDataReaderImpl.CountHiddenColumns(m_addRowidDoneImplicitly);
				goto end_IL_004b;
				IL_00ba:
				if (connectionImpl.m_statementCache != null)
				{
					ValidateStatementCacheSize(connectionImpl);
				}
				byte[] sqlStmtByteStream = connectionImpl.m_marshallingEngine.m_dbCharSetConv.ConvertStringToBytes(commandText, 0, commandText.Length);
				ArrayList placeHolderCollection = null;
				if (m_bBindByName)
				{
					placeHolderCollection = new ArrayList();
				}
				bool bBindParamPresent = true;
				if (commandType == CommandType.Text && (ConfigBaseClass.m_bUseLegacyLocalParser || flag2))
				{
					ParseCommandText(cmdText, ref bBindParamPresent, ref placeHolderCollection);
				}
				OracleParameterCollection oracleParameterCollection = null;
				oracleParameterCollection = ((!m_bBindByName || paramColl == null || paramColl.Count <= 0) ? paramColl : ((commandType != CommandType.StoredProcedure) ? GetBindByPositionBasedParameterCollection(paramColl, placeHolderCollection) : ReorderBindByNameBasedParameterCollectionForStoredProcedure(paramColl)));
				bool bBindMetadataModified = false;
				TTCExecuteSql.MarshalBindParameterValueHelper marshalBindValuesHelper = TTCExecuteSql.MarshalBindParameterValueHelper.Null;
				marshalBindValuesHelper.m_bWriteOutParamVal = false;
				if (bBindParamPresent && oracleParameterCollection != null)
				{
					marshalBindValuesHelper.m_sqlStmtType = m_sqlStatementType;
					if (m_bindAccessors == null || m_bindAccessors.Length != paramColl.Count)
					{
						m_bindAccessors = new Accessor[paramColl.Count];
					}
					ProcessParameters(oracleParameterCollection, connectionImpl, null, ref bBindMetadataModified, isEFSelectStatement: false, ref marshalBindValuesHelper);
				}
				else
				{
					m_bindAccessors = null;
					m_bindDirectionsFromServer = null;
					m_arrayBindCount = 0;
				}
				if (!ProviderConfig.m_bTraceLevelSecure && ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.SQL, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata, commandText);
				}
				try
				{
					connectionImpl.WaitForConnectionForExecution();
					connectionImpl.AddAllPiggyBackRequests();
					TTCExecuteSql executeSqlObject = connectionImpl.ExecuteSqlObject;
					long[] array = new long[2];
					List<TTCResultSet> implicitRSList = null;
					if (commandType == CommandType.TableDirect)
					{
						m_bHasReturningClause = false;
						if (ProviderConfig.m_bTraceLevelPublic)
						{
							Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata, "Cmd Text (TableDirect): " + commandText + "\nHas Returning Clause: " + m_bHasReturningClause);
						}
					}
					else
					{
						m_bHasReturningClause = HasReturningClause(cmdText, m_sqlStatementType, paramColl, placeHolderCollection, bBindParamPresent);
						if (ProviderConfig.m_bTraceLevelPublic)
						{
							Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata, "Cmd Text (SQL): " + commandText + "\nHas Returning Clause: " + m_bHasReturningClause);
						}
					}
					executeSqlObject.SendExecuteRequest(connectionImpl, sqlStmtByteStream, m_bHasReturningClause, 0, null, 0L, null, 0L, parse: true, execute: false, fetch: false, define: false, bAutoCommit: false, bDisableCompressedFetch: false, m_sqlStatementType, 0, m_arrayBindCount, array, ref marshalBindValuesHelper, 0);
					int noOfRowsFetched = 0;
					long queryId = 0L;
					Accessor[] defineAccessors = null;
					DataUnmarshaller dataUnmarshaller = null;
					if (marshalBindValuesHelper.m_bindDirections == null && marshalBindValuesHelper.m_paramValueArray != null)
					{
						marshalBindValuesHelper.ResetBindDirections(paramColl.Count);
						marshalBindValuesHelper.m_bAllInBinds = true;
					}
					executeSqlObject.ReceiveExecuteResponse(ref defineAccessors, m_bindAccessors, m_bHasReturningClause, ref sqlMetadata, m_sqlStatementType, -1L, 0, out noOfRowsFetched, ref queryId, 0, 0L, 0L, 0L, array, marshalBindValuesHelper.m_bAllInBinds, m_arrayBindCount, ref dataUnmarshaller, ref marshalBindValuesHelper, out m_rowsAffectedPerBind, bDefineDone: false, ref bMoreThanOneRowAffectedByDmlWithRetClause, ref implicitRSList);
					int cursorId = 0;
					bool hasMoreRowsInDB = false;
					OracleException exceptionForArrayBindDML = null;
					VerifyExecution(connectionImpl, out cursorId, bThrowArrayBindRelatedErrors: true, ref exceptionForArrayBindDML, out hasMoreRowsInDB, bFirstIterationDone: true);
					m_sessionTimeZone = connectionImpl.m_sessionTimeZone;
					if (sqlMetadata != null)
					{
						sqlMetadata.pCommandText = commandText;
					}
					if (cursorId != 0)
					{
						connectionImpl.AddCursorIdToBeClosed(cursorId);
					}
				}
				finally
				{
					connectionImpl.m_connectionFreeToUseEvent.Set();
				}
				goto IL_03b9;
				end_IL_004b:;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata, ex);
				if (ex is OracleException)
				{
					connectionImpl.m_lastErrorNum = ((OracleException)ex).Number;
				}
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.RetrieveMetadata);
				}
			}
		}

		internal void ParseCommandText(string commandText, ref bool bBindParamPresent, ref ArrayList placeHolderCollection)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ParseCommandText);
			}
			int i = 0;
			bBindParamPresent = false;
			try
			{
				int length = commandText.Length;
				while (i < length)
				{
					char c = commandText[i];
					if (c == '\'')
					{
						for (i++; i < length && commandText[i] != '\''; i++)
						{
						}
						if (i >= length)
						{
							break;
						}
						c = commandText[i];
					}
					if (c == '"')
					{
						for (i++; i < length && commandText[i] != '"'; i++)
						{
						}
						if (i >= length)
						{
							break;
						}
						c = commandText[i];
					}
					int num = length - 1;
					if (c == '/' && i < num && commandText[i + 1] == '*')
					{
						for (i += 2; i < length; i++)
						{
							if (i >= num || commandText[i] == '*' || commandText[i + 1] == '/')
							{
								i += 2;
								break;
							}
						}
						if (i >= length)
						{
							break;
						}
						c = commandText[i];
					}
					if (c == '-' && i < num && commandText[i + 1] == '-')
					{
						i += 2;
						while (i < length && commandText[i++] != '\n')
						{
						}
						if (i >= length)
						{
							break;
						}
						c = commandText[i];
					}
					if (c == ':')
					{
						for (i++; i < length && commandText[i] == ' '; i++)
						{
						}
						if (i >= length)
						{
							break;
						}
						c = commandText[i];
						if (i + 3 < length && commandText[i + 3] == '.' && (((c == 'N' || c == 'n') && (c == 'E' || c == 'e') && (c == 'W' || c == 'w')) || ((c == 'O' || c == 'o') && (c == 'L' || c == 'l') && (c == 'D' || c == 'd'))))
						{
							continue;
						}
						if (c != '=')
						{
							bBindParamPresent = true;
							if (placeHolderCollection == null)
							{
								break;
							}
							placeHolderCollection.Add(GetPlaceHolderName(commandText, i, length));
						}
					}
					i++;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ParseCommandText, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ParseCommandText);
				}
			}
		}

		private string GetPlaceHolderName(string commandText, int index, int strLength)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetPlaceHolderName);
			}
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				int num = index;
				char c = commandText[num];
				while (char.IsLetterOrDigit(c) || c == '_' || c == '#' || c == '$' || c == '"')
				{
					stringBuilder.Append(c);
					if (num + 1 >= strLength)
					{
						break;
					}
					c = commandText[++num];
				}
				return stringBuilder.ToString();
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetPlaceHolderName, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetPlaceHolderName);
				}
			}
		}

		private OracleParameterCollection ReorderBindByNameBasedParameterCollectionForStoredProcedure(OracleParameterCollection orclParamColl)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ReorderBindByNameBasedParameterCollectionForStoredProcedure);
			}
			try
			{
				OracleParameterCollection oracleParameterCollection = null;
				if (orclParamColl != null)
				{
					ArrayList arrayList = new ArrayList();
					OracleParameter oracleParameter = null;
					foreach (OracleParameter item in orclParamColl)
					{
						if (item.Direction == ParameterDirection.ReturnValue)
						{
							oracleParameter = item;
						}
						else
						{
							arrayList.Add(item);
						}
					}
					oracleParameterCollection = new OracleParameterCollection(arrayList);
					if (oracleParameter != null)
					{
						oracleParameter.m_collRef = null;
						oracleParameterCollection.Insert(0, oracleParameter);
					}
				}
				return oracleParameterCollection;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ReorderBindByNameBasedParameterCollectionForStoredProcedure, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.ReorderBindByNameBasedParameterCollectionForStoredProcedure);
				}
			}
		}

		internal OracleParameterCollection GetBindByPositionBasedParameterCollection(OracleParameterCollection orclParamColl, ArrayList placeHolderCollection, bool bXmlQuerySave = false)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262400, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetBindByPositionBasedParameterCollection);
			}
			ArrayList arrayList = null;
			try
			{
				if (placeHolderCollection != null && placeHolderCollection.Count > 0)
				{
					arrayList = new ArrayList();
					OracleParameter oracleParameter = null;
					int num = -1;
					foreach (string item in placeHolderCollection)
					{
						if (bXmlQuerySave)
						{
							if ((num = orclParamColl.FindLastParamByName(item)) != -1)
							{
								oracleParameter = orclParamColl[num];
							}
						}
						else
						{
							oracleParameter = orclParamColl[item];
						}
						if (oracleParameter == null)
						{
							string name = ":" + item;
							if (bXmlQuerySave)
							{
								if ((num = orclParamColl.FindLastParamByName(name)) != -1)
								{
									oracleParameter = orclParamColl[num];
								}
							}
							else
							{
								oracleParameter = orclParamColl[name];
							}
						}
						if (oracleParameter != null)
						{
							if (!arrayList.Contains(oracleParameter))
							{
								arrayList.Add(oracleParameter);
							}
							else if (m_sqlStatementType != SqlStatementType.PLSQL)
							{
								OracleParameter oracleParameter2 = (OracleParameter)oracleParameter.Clone();
								oracleParameter2.DuplicateBind = true;
								arrayList.Add(oracleParameter2);
							}
							continue;
						}
						throw new ArgumentException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.PRM_INVALID_BIND), item);
					}
					return new OracleParameterCollection(arrayList);
				}
				return null;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, (OracleTraceTag)268697600, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetBindByPositionBasedParameterCollection, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, (OracleTraceTag)262656, OracleTraceClassName.OracleCommandImpl, OracleTraceFuncName.GetBindByPositionBasedParameterCollection);
				}
			}
		}

		internal void CloseImplicitRefCursors(OracleConnectionImpl connectionImpl)
		{
			for (int i = 0; i < m_implicitRSList.Count; i++)
			{
				connectionImpl.AddCursorIdToBeClosed(m_implicitRSList[i].CursorId);
			}
			m_implicitRSList = null;
		}

		private void BuildXmlQueryCommandText(bool wantResult, string resultParamName, bool isOracle8i, string commandText, OracleParameterCollection parameters, OracleXmlCommandType xmlCommandType, OracleXmlQueryProperties xmlQueryProperties)
		{
			int num = 0;
			int num2 = 0;
			bool flag = false;
			string text = string.Empty;
			string text2 = string.Empty;
			m_pooledCmdText = commandText;
			StringBuilder stringBuilder = new StringBuilder(4096);
			if (xmlQueryProperties == null)
			{
				xmlQueryProperties = new OracleXmlQueryProperties();
			}
			if (xmlQueryProperties.Xslt != null && xmlQueryProperties.Xslt.Length != 0)
			{
				flag = true;
			}
			if (xmlQueryProperties.RootTag != null && xmlQueryProperties.RootTag.Length != 0)
			{
				text = xmlQueryProperties.RootTag;
			}
			if (xmlQueryProperties.RowTag != null && xmlQueryProperties.RowTag.Length != 0)
			{
				text2 = xmlQueryProperties.RowTag;
			}
			if (isOracle8i)
			{
				stringBuilder.Append("declare ");
				stringBuilder.Append("ctx DBMS_XMLQUERY.ctxType; ");
				if (!wantResult)
				{
					stringBuilder.Append("OracleResult CLOB; ");
				}
				stringBuilder.Append("begin ");
				stringBuilder.Append("ctx := DBMS_XMLQUERY.newContext(:OracleSqlQuery$); ");
				stringBuilder.Append("DBMS_XMLQUERY.setRaiseException(ctx, true); ");
				stringBuilder.Append("DBMS_XMLQUERY.setRowIdAttrName(ctx, ''); ");
				stringBuilder.Append("DBMS_XMLQUERY.setDateFormat(ctx, 'yyyy-MM-dd''T''HH:mm:ss.SSS'); ");
				stringBuilder.Append("DBMS_XMLQUERY.useTypeForCollElemTag(ctx); ");
				if (!text.Equals("ROWSET"))
				{
					stringBuilder.Append("DBMS_XMLQUERY.setRowsetTag(ctx, '");
					stringBuilder.Append(text);
					stringBuilder.Append("'); ");
				}
				if (!text2.Equals("ROW"))
				{
					stringBuilder.Append("DBMS_XMLQUERY.setRowTag(ctx, '");
					stringBuilder.Append(text2);
					stringBuilder.Append("'); ");
				}
				if (xmlQueryProperties.MaxRows > -1)
				{
					stringBuilder.Append("DBMS_XMLQUERY.setMaxRows(ctx, '");
					stringBuilder.Append(xmlQueryProperties.MaxRows.ToString());
					stringBuilder.Append("'); ");
				}
				if (parameters != null)
				{
					num = parameters.Count;
				}
				for (num2 = 0; num2 < num; num2++)
				{
					string text3 = parameters[num2].ParameterName.Trim();
					stringBuilder.Append("DBMS_XMLQUERY.setBindValue(ctx, '");
					stringBuilder.Append(text3.Substring(1));
					stringBuilder.Append("', ");
					stringBuilder.Append(text3);
					stringBuilder.Append("); ");
				}
				if (flag)
				{
					stringBuilder.Append("DBMS_XMLQUERY.setXSLT(ctx, :OracleXslDoc$, ''); ");
				}
				if (wantResult)
				{
					stringBuilder.Append(resultParamName);
				}
				else
				{
					stringBuilder.Append("OracleResult");
				}
				stringBuilder.Append(" := DBMS_XMLQUERY.getXML(ctx); ");
				stringBuilder.Append("DBMS_XMLQUERY.closeContext(ctx); ");
				stringBuilder.Append("end;");
			}
			else
			{
				stringBuilder.Append("declare ");
				stringBuilder.Append("ctx DBMS_XMLGEN.ctxHandle; ");
				stringBuilder.Append("refcur SYS_REFCURSOR; ");
				if (!wantResult)
				{
					stringBuilder.Append("OracleResult CLOB; ");
				}
				if (flag)
				{
					stringBuilder.Append("xmlClob CLOB; ");
					stringBuilder.Append("tmpClob CLOB; ");
					stringBuilder.Append("p DBMS_XMLPARSER.Parser; ");
					stringBuilder.Append("xmldoc DBMS_XMLDOM.DOMDocument; ");
					stringBuilder.Append("xsldoc DBMS_XMLDOM.DOMDocument; ");
					stringBuilder.Append("ss DBMS_XSLPROCESSOR.Stylesheet; ");
					stringBuilder.Append("proc DBMS_XSLPROCESSOR.Processor; ");
				}
				stringBuilder.Append("begin ");
				m_pooledCmdText = m_pooledCmdText.Trim();
				stringBuilder.Append("OPEN refcur FOR ");
				stringBuilder.Append(m_pooledCmdText);
				if (m_pooledCmdText.EndsWith(";"))
				{
					stringBuilder.Append(" ");
				}
				else
				{
					stringBuilder.Append("; ");
				}
				stringBuilder.Append("ctx := DBMS_XMLGEN.newContext(refcur); ");
				if (!text.Equals("ROWSET"))
				{
					stringBuilder.Append("DBMS_XMLGEN.setRowSetTag(ctx, '");
					stringBuilder.Append(text);
					stringBuilder.Append("'); ");
				}
				if (!text2.Equals("ROW"))
				{
					stringBuilder.Append("DBMS_XMLGEN.setRowTag(ctx, '");
					stringBuilder.Append(text2);
					stringBuilder.Append("'); ");
				}
				if (xmlQueryProperties.MaxRows > -1)
				{
					stringBuilder.Append("DBMS_XMLGEN.setMaxRows(ctx, '");
					stringBuilder.Append(xmlQueryProperties.MaxRows.ToString());
					stringBuilder.Append("'); ");
				}
				if (flag)
				{
					stringBuilder.Append("xmlClob");
				}
				else if (wantResult)
				{
					stringBuilder.Append(resultParamName);
				}
				else
				{
					stringBuilder.Append("OracleResult");
				}
				stringBuilder.Append(" := DBMS_XMLGEN.getXML(ctx); ");
				stringBuilder.Append("DBMS_XMLGEN.closeContext(ctx); ");
				stringBuilder.Append("CLOSE refcur; ");
				if (flag)
				{
					Build9iXslCommandTextForXmlGen(stringBuilder, wantResult, xmlQueryProperties.XsltParams, commandText, xmlCommandType, xmlQueryProperties, null);
				}
				stringBuilder.Append("end;");
			}
			m_pooledCmdText = stringBuilder.ToString();
		}

		private void BuildXmlSaveCommandText(OracleConnection connection, string commandText, OracleXmlCommandType xmlCommandType, OracleXmlSaveProperties xmlSaveProperties)
		{
			int num = 0;
			bool flag = false;
			bool flag2 = false;
			int num2 = 0;
			string[] xsltParamNames = null;
			string[] xsltParamValues = null;
			string text = string.Empty;
			int majorVersion = connection.m_majorVersion;
			int minorVersion = connection.m_minorVersion;
			if ((majorVersion == 8 && minorVersion == 1) || (majorVersion == 9 && minorVersion == 0))
			{
				flag = true;
			}
			StringBuilder stringBuilder = new StringBuilder(4096);
			if (xmlSaveProperties == null)
			{
				xmlSaveProperties = new OracleXmlSaveProperties();
			}
			if (xmlSaveProperties.Xslt != null && xmlSaveProperties.Xslt.Length != 0)
			{
				flag2 = true;
			}
			if (xmlSaveProperties.RowTag != null && xmlSaveProperties.RowTag.Length != 0)
			{
				text = xmlSaveProperties.RowTag;
			}
			stringBuilder.Append("declare ");
			stringBuilder.Append("ctx DBMS_XMLSAVE.ctxType; ");
			if (flag && flag2)
			{
				stringBuilder.Append("xmlClob CLOB; ");
				stringBuilder.Append("tmpClob CLOB; ");
				stringBuilder.Append("p XMLPARSER.Parser; ");
				stringBuilder.Append("xmldoc XMLDOM.DOMDocument; ");
				stringBuilder.Append("xsldoc XMLDOM.DOMDocument; ");
				stringBuilder.Append("ss XSLPROCESSOR.Stylesheet; ");
				stringBuilder.Append("proc XSLPROCESSOR.Processor; ");
			}
			stringBuilder.Append("begin ");
			if (flag && flag2)
			{
				Build8iXslCommandTextForXmlSave(stringBuilder, xmlSaveProperties.XsltParams, commandText, xmlSaveProperties);
			}
			stringBuilder.Append("ctx := DBMS_XMLSAVE.newContext(:OracleTableName$); ");
			if (!text.Equals("ROW"))
			{
				stringBuilder.Append("DBMS_XMLSAVE.setRowTag(ctx, '");
				stringBuilder.Append(text);
				stringBuilder.Append("'); ");
			}
			stringBuilder.Append("DBMS_XMLSAVE.setIgnoreCase(ctx, DBMS_XMLSAVE.MATCH_CASE); ");
			if (!flag)
			{
				stringBuilder.Append("DBMS_XMLSAVE.setSQLToXMLNameEscaping(ctx, true); ");
			}
			stringBuilder.Append("DBMS_XMLSAVE.setDateFormat(ctx, 'yyyy-MM-dd''T''HH:mm:ss.SSS'); ");
			if (xmlSaveProperties.KeyColumnsList != null)
			{
				for (num = 0; num < xmlSaveProperties.KeyColumnsList.Length && xmlSaveProperties.KeyColumnsList[num] != null; num++)
				{
					stringBuilder.Append("DBMS_XMLSAVE.setKeyColumn(ctx, '");
					stringBuilder.Append(xmlSaveProperties.KeyColumnsList[num]);
					stringBuilder.Append("'); ");
				}
			}
			if (xmlSaveProperties.UpdateColumnsList != null)
			{
				for (num = 0; num < xmlSaveProperties.UpdateColumnsList.Length && xmlSaveProperties.UpdateColumnsList[num] != null; num++)
				{
					stringBuilder.Append("DBMS_XMLSAVE.setUpdateColumn(ctx, '");
					stringBuilder.Append(xmlSaveProperties.UpdateColumnsList[num]);
					stringBuilder.Append("'); ");
				}
			}
			if (!flag && flag2)
			{
				stringBuilder.Append("DBMS_XMLSAVE.setXSLT(ctx, :OracleXslDoc$, ''); ");
				num2 = ParseXsltParams(xmlSaveProperties.XsltParams, out xsltParamNames, out xsltParamValues);
				for (num = 0; num < num2; num++)
				{
					stringBuilder.Append("DBMS_XMLSAVE.setXSLTParam(ctx, '");
					stringBuilder.Append(xsltParamNames[num]);
					stringBuilder.Append("', '");
					stringBuilder.Append(xsltParamValues[num]);
					stringBuilder.Append("'); ");
				}
			}
			stringBuilder.Append(":OracleResult$");
			if (flag && flag2)
			{
				if (OracleXmlCommandType.Insert == xmlCommandType)
				{
					stringBuilder.Append(" := DBMS_XMLSAVE.insertXML(ctx, xmlClob); ");
				}
				else if (OracleXmlCommandType.Update == xmlCommandType)
				{
					stringBuilder.Append(" := DBMS_XMLSAVE.updateXML(ctx, xmlClob); ");
				}
				else if (OracleXmlCommandType.Delete == xmlCommandType)
				{
					stringBuilder.Append(" := DBMS_XMLSAVE.deleteXML(ctx, xmlClob); ");
				}
			}
			else if (OracleXmlCommandType.Insert == xmlCommandType)
			{
				stringBuilder.Append(" := DBMS_XMLSAVE.insertXML(ctx, :OracleXmlDoc$); ");
			}
			else if (OracleXmlCommandType.Update == xmlCommandType)
			{
				stringBuilder.Append(" := DBMS_XMLSAVE.updateXML(ctx, :OracleXmlDoc$); ");
			}
			else if (OracleXmlCommandType.Delete == xmlCommandType)
			{
				stringBuilder.Append(" := DBMS_XMLSAVE.deleteXML(ctx, :OracleXmlDoc$); ");
			}
			stringBuilder.Append("DBMS_XMLSAVE.closeContext(ctx); ");
			if (flag && flag2)
			{
				stringBuilder.Append("dbms_lob.freetemporary(xmlClob); ");
			}
			stringBuilder.Append("end;");
			m_pooledCmdText = stringBuilder.ToString();
		}

		private void Build8iXslCommandTextForXmlSave(StringBuilder strBldr, string xsltParams, string commandText, OracleXmlSaveProperties xmlSaveProperties)
		{
			int num = 0;
			string[] xsltParamNames = null;
			string[] xsltParamValues = null;
			int num2 = 0;
			string value = ":OracleXmlDoc$";
			string value2 = "xmlClob";
			strBldr.Append("dbms_lob.createtemporary(tmpClob, TRUE); ");
			strBldr.Append("p := XMLPARSER.newParser; ");
			strBldr.Append("XMLPARSER.setValidationMode(p, FALSE); ");
			strBldr.Append("XMLPARSER.setPreserveWhiteSpace(p, TRUE); ");
			if (commandText.Length > 32512)
			{
				strBldr.Append("XMLPARSER.parseClob(p, ");
			}
			else
			{
				strBldr.Append("XMLPARSER.parseBuffer(p, ");
			}
			strBldr.Append(value);
			strBldr.Append("); ");
			strBldr.Append("xmldoc := XMLPARSER.getDocument(p); ");
			if (xmlSaveProperties == null)
			{
				xmlSaveProperties = new OracleXmlSaveProperties();
			}
			if (xmlSaveProperties.Xslt.Length > 32512)
			{
				strBldr.Append("XMLPARSER.parseClob(p, :OracleXslDoc$); ");
			}
			else
			{
				strBldr.Append("XMLPARSER.parseBuffer(p, :OracleXslDoc$); ");
			}
			strBldr.Append("xsldoc := XMLPARSER.getDocument(p); ");
			strBldr.Append("ss := XSLPROCESSOR.newStylesheet(xsldoc, ''); ");
			num = ParseXsltParams(xsltParams, out xsltParamNames, out xsltParamValues);
			for (num2 = 0; num2 < num; num2++)
			{
				strBldr.Append("XSLPROCESSOR.setParam(ss, '");
				strBldr.Append(xsltParamNames[num2]);
				strBldr.Append("', '");
				strBldr.Append(xsltParamValues[num2]);
				strBldr.Append("'); ");
			}
			strBldr.Append("proc := XSLPROCESSOR.newProcessor; ");
			strBldr.Append("XSLPROCESSOR.processXSL(proc, ss, xmldoc, tmpClob); ");
			strBldr.Append(value2);
			strBldr.Append(" := tmpClob; ");
			strBldr.Append("XMLDOM.freeDocument(xmldoc); ");
			strBldr.Append("XMLDOM.freeDocument(xsldoc); ");
			strBldr.Append("XSLPROCESSOR.freeProcessor(proc); ");
			strBldr.Append("XSLPROCESSOR.freeStylesheet(ss); ");
			strBldr.Append("XMLPARSER.freeParser(p); ");
		}

		private void Build9iXslCommandTextForXmlGen(StringBuilder strBldr, bool wantResult, string xsltParams, string commandText, OracleXmlCommandType xmlCommandType, OracleXmlQueryProperties xmlQueryProperties, OracleXmlSaveProperties xmlSaveProperties)
		{
			int num = 0;
			string[] xsltParamNames = null;
			string[] xsltParamValues = null;
			int num2 = 0;
			string text = null;
			string text2 = null;
			if (OracleXmlCommandType.Query == xmlCommandType)
			{
				text = "xmlClob";
				text2 = ((!wantResult) ? "OracleResult" : ":OracleResult$");
			}
			else
			{
				text = ":OracleXmlDoc$";
				text2 = "xmlClob";
			}
			strBldr.Append("dbms_lob.createtemporary(tmpClob, TRUE); ");
			strBldr.Append("p := DBMS_XMLPARSER.newParser; ");
			strBldr.Append("DBMS_XMLPARSER.setValidationMode(p, FALSE); ");
			strBldr.Append("DBMS_XMLPARSER.setPreserveWhiteSpace(p, TRUE); ");
			if (OracleXmlCommandType.Query == xmlCommandType || commandText.Length > 32512)
			{
				strBldr.Append("DBMS_XMLPARSER.parseClob(p, ");
			}
			else
			{
				strBldr.Append("DBMS_XMLPARSER.parseBuffer(p, ");
			}
			strBldr.Append(text);
			strBldr.Append("); ");
			strBldr.Append("xmldoc := DBMS_XMLPARSER.getDocument(p); ");
			if (xmlQueryProperties == null)
			{
				xmlQueryProperties = new OracleXmlQueryProperties();
			}
			if (xmlSaveProperties == null)
			{
				xmlSaveProperties = new OracleXmlSaveProperties();
			}
			if ((OracleXmlCommandType.Query == xmlCommandType && xmlQueryProperties.Xslt.Length > 32512) || (OracleXmlCommandType.Query != xmlCommandType && xmlSaveProperties.Xslt.Length > 32512))
			{
				strBldr.Append("DBMS_XMLPARSER.parseClob(p, :OracleXslDoc$); ");
			}
			else
			{
				strBldr.Append("DBMS_XMLPARSER.parseBuffer(p, :OracleXslDoc$); ");
			}
			strBldr.Append("xsldoc := DBMS_XMLPARSER.getDocument(p); ");
			strBldr.Append("ss := DBMS_XSLPROCESSOR.newStylesheet(xsldoc, ''); ");
			num = ParseXsltParams(xsltParams, out xsltParamNames, out xsltParamValues);
			for (num2 = 0; num2 < num; num2++)
			{
				strBldr.Append("DBMS_XSLPROCESSOR.setParam(ss, '");
				strBldr.Append(xsltParamNames[num2]);
				strBldr.Append("', '");
				strBldr.Append(xsltParamValues[num2]);
				strBldr.Append("'); ");
			}
			strBldr.Append("proc := DBMS_XSLPROCESSOR.newProcessor; ");
			strBldr.Append("DBMS_XSLPROCESSOR.processXSL(proc, ss, xmldoc, tmpClob); ");
			strBldr.Append(text2);
			strBldr.Append(" := tmpClob; ");
			strBldr.Append("DBMS_XMLDOM.freeDocument(xmldoc); ");
			strBldr.Append("DBMS_XMLDOM.freeDocument(xsldoc); ");
			strBldr.Append("DBMS_XSLPROCESSOR.freeProcessor(proc); ");
			strBldr.Append("DBMS_XSLPROCESSOR.freeStylesheet(ss); ");
			strBldr.Append("DBMS_XMLPARSER.freeParser(p); ");
			strBldr.Append("dbms_lob.freetemporary(tmpClob); ");
		}

		private int ParseXsltParams(string xsltParams, out string[] xsltParamNames, out string[] xsltParamValues)
		{
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			string text = null;
			string text2 = null;
			string text3 = null;
			int num5 = 1;
			int num6 = 0;
			int num7 = 0;
			xsltParamNames = null;
			xsltParamValues = null;
			if (xsltParams == null || xsltParams.Length == 0)
			{
				return num6;
			}
			num = 0;
			while (-1 != (num3 = xsltParams.IndexOf(";", num)))
			{
				num5++;
				num = num3 + 1;
			}
			xsltParamNames = new string[num5];
			xsltParamValues = new string[num5];
			num = 0;
			for (num7 = 0; num7 < num5; num7++)
			{
				num3 = xsltParams.IndexOf(";", num);
				num2 = ((-1 != num3) ? num3 : xsltParams.Length);
				text = xsltParams.Substring(num, num2 - num);
				if (text != null && text.Length != 0 && -1 != (num4 = text.IndexOf("=")))
				{
					text2 = text.Substring(0, num4).Trim();
					if (text2 != null && text2.Length != 0)
					{
						text3 = text.Substring(num4 + 1).Trim();
						xsltParamNames[num6] = text2;
						xsltParamValues[num6] = text3;
						num6++;
					}
				}
				num = num2 + 1;
			}
			return num6;
		}
	}
}
